Hente data ud fra en MySQL Database
HejJeg har lidt problemer med at hente nogle data ud fra en MySQL database og sætte dem i en CheckedListBox er der nogen der kan hjælpe ?
Her er CheckListBox'en:
' Stop the ListBox from drawing while items are added.
CheckedListBox1.BeginUpdate()
' Loop through and add five thousand new items.
Dim x As Integer
For x = 1 To 499
CheckedListBox1.Items.Add("Item " & x.ToString())
Next x
' End the update process and force a repaint of the ListBox.
CheckedListBox1.EndUpdate()
'End Sub
Her er min database forbindelse:
Dim SQL1 As String
Dim CreateUser
SQL1 = "Selece * from Users"
CreateUser = DatabaseForbindelse(SQL1)
Og her er funktionen DatabaseForBindelse:
Function DatabaseForbindelse(ByVal sqlstring As String)
Dim conn As MySqlConnection
'connect to DB
conn = New MySqlConnection()
conn.ConnectionString = "server=192.168.42.108; user id=root; password=******; database=Updater"
'see if connection failed.
Try
conn.Open()
Catch myerror As MySqlException
MessageBox.Show("Error Connecting to Database: " & myerror.Message)
End Try
'sql query
Dim myAdapter As New MySqlDataAdapter
Dim sqlquery = "" & sqlstring & ""
Dim myCommand As New MySqlCommand()
myCommand.Connection = conn
myCommand.CommandText = sqlquery
'start(query)
myAdapter.SelectCommand = myCommand
Dim myData As MySqlDataReader
myData = myCommand.ExecuteReader()
'MessageBox.Show(myData.GetValues(msg))
Return myData
End Function