28-08-14, 09:38 AM
السلام عليكم
اخواني قبل كل شي بحثت في المنتدى عن هذه الطريقه ولم اجدها
وبعض المواضيع متشابهه وبعضها تتعلق بقاعدة بيانات mysql و mysql server
انا رفعت قاعدة بيانات على موقع مجاني من نوع mysql
واستخدمت عدة اكواد على الفيجوال بيسك دوت نت بدون فائدة
وهذا هو الكود الذي استخدمه في الفيجوال بيسك
لم اجد الطريقة في بعض مواقع الانترنت واتمنى ان اجدها هنا
علما بأن قاعدة البيانات مستخدمه في موقع مجاني اسمه
hostinger.ae
شكرا لكم
اخواني قبل كل شي بحثت في المنتدى عن هذه الطريقه ولم اجدها
وبعض المواضيع متشابهه وبعضها تتعلق بقاعدة بيانات mysql و mysql server
انا رفعت قاعدة بيانات على موقع مجاني من نوع mysql
واستخدمت عدة اكواد على الفيجوال بيسك دوت نت بدون فائدة
وهذا هو الكود الذي استخدمه في الفيجوال بيسك
PHP كود :
Imports System.Data
Imports MySql.Data.MySqlClient
Public Class Manage_user
Dim con As New MySqlConnection
Dim result As Integer
'MySqlCommand It represents a SQL statement to execute against a MySQL Database
Dim cmd As New MySqlCommand
'Represents a set of data commands and a database connection that
'are used to fill a dataset and update a MySQL database. This class cannot be inherited.
Dim da As New MySqlDataAdapter
Private Sub btncreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncreate.Click
'this line of is simply we copy this one from our form
con.ConnectionString = ("server=localhost;user id=root;password=;database=androidhive")
Try
'we open Connection
con.Open()
With cmd
.Connection = con
.CommandText = "INSERT INTO `androidhive`.`products` (`pid`, `name`, `price`, `description`) " & _
"VALUES (NULL, '" & txtfullname.Text & "', '" & txtusername.Text & "', '" & txtpassword.Text & "');"
'in this line it Executes a transact-SQL statements against the connection and returns the number of rows affected
result = cmd.ExecuteNonQuery
'if the result is equal to zero it means that no rows is inserted or somethings wrong during the execution
If result = 0 Then
MsgBox("Data has been Inserted!")
Else
MsgBox("Successfully saved!")
End If
End With
Catch ex As Exception
MsgBox(ex.Message)
End Try
con.Close()
End Sub
Private Sub btnload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnload.Click
'again we do this because we do not yet declare this as global, but we do it for now beacause in later tutorial
'we will do the moduling and more on refactoring of codes
con.ConnectionString = ("server=localhost;user id=root;password=;database=androidhive")
Try
con.Open()
With cmd
.Connection = con
'in this query it does simply selecting or getting all the user found in the database.
.CommandText = "Select * from products"
End With
Catch ex As Exception
MsgBox(ex.Message)
End Try
con.Close()
da.Dispose()
filltable(dtguser)
End Sub
' this our sub procedure that well always used
'this beacause it always catch all the result query
'and it will display to any kind of visual basic containers like datagridview,listbox,listview, etc...
Public Sub filltable(ByVal dtgrd As Object)
'declare a variable as new datatable
Dim publictable As New DataTable
Try
'Gets or sets an SQL statement or stored procedure used to select records in the database.
da.SelectCommand = cmd
da.Fill(publictable)
dtgrd.DataSource = publictable
dtgrd.Columns(0).Visible = False
da.Dispose()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub Manage_user_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
لم اجد الطريقة في بعض مواقع الانترنت واتمنى ان اجدها هنا
علما بأن قاعدة البيانات مستخدمه في موقع مجاني اسمه
hostinger.ae
شكرا لكم