mySQL and Display in Listbox
I'm trying! I have my book, but it won't show mySQL examples.
I think I've sucessfully got vb to reconize the database. I can go to the data manager and view the tables and whatnot.
I just need to know where the right place to look at to find out what code I need to use to grab information from the table. I'm not seeing any smart drop down vars so I'm real confused.
Just need to grab the info from the database and put it into a listbox :)
Thanks for the help.
Re: mySQL and Display in Listbox
I have not used mySQL yet but I think you need to create recordsets in order to grab data from your database.
Re: mySQL and Display in Listbox
Alright This works perfectly!
VB Code:
Private Sub Form_Load()
'==============================
Dim rs As New ADODB.Recordset
Dim cn As New ADODB.Connection
Dim ITM As ListItem
cn.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;" & _
"DATABASE=Pizazzy;USER=;PASSWORD=;OPTION=3;"
cn.Open
sql = "SELECT * FROM Messages"
rs.Open sql, cn, adOpenForwardOnly, adLockOptimistic
ListView1.View = lvwReport
ListView1.ColumnHeaders.Add 1, , "From"
ListView1.ColumnHeaders.Add 2, , "Message"
With rs
Do Until rs.EOF = True
Set ITM = ListView1.ListItems.Add(1, "", Trim(!From))
ITM.SubItems(1) = IIf(IsNull(!Msg), "", Trim(!Msg))
.MoveNext
Loop
End With
End Sub