Connecting to MySQL Database from VB2005
Hey folks :)
I'm trying to connect to a MySQL database using VB2005.
I have made a small module, and it works just fine. I used ADO to connect with.
Now i have my problem: How do I extract the values from the table?
I can count the number of rows, but i cant find a way to actually show the data from a speific column in fx a ListBox.
I would be very happy if someone could help me with this!
Here's my code:
Module modConnect
Dim strDataBaseName As String
Dim strDBCursorType As String
Dim strDBLockType As String
Dim strDBOptions As String
Dim rs As ADODB.Recordset
Dim cn As ADODB.Connection
Public Function Connect() As Boolean
Dim intCount As Long
Dim strSQL As String
cn = New ADODB.Connection
cn.Open(ConnectString())
With cn
.CommandTimeout = 0
.CursorLocation = ADODB.CursorLocationEnum.adUseClient
End With
rs = New ADODB.Recordset
strSQL = "SELECT * FROM radio"
rs.Open(strSQL, cn, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic)
If Not rs.EOF Then
For intCount = 1 To rs.RecordCount
'Its here i want to get the data from a specific column and show it in my
'ListBox.
Next intCount
End If
End Function
Private Function ConnectString() As String
Dim strServerName As String
Dim strDatabaseName As String
Dim strUserName As String
Dim strPassword As String
strServerName = "192.168.1.7"
strDatabaseName = "radiocenter"
strUserName = "admin"
strPassword = "1234"
ConnectString = "DRIVER={MySQL ODBC 3.51 Driver};" & "SERVER=" & strServerName & ";DATABASE=" & strDatabaseName & ";" & "USER=" & strUserName & ";PASSWORD=" & strPassword & ";Port=3306;" & Chr(34) & ";"
End Function
End Module
Thanks in advance!
- Tank
|