Help Troubleshooting Code (ADO.NET)

  • Thread starter Thread starter joshfeingold
  • Start date Start date
J

joshfeingold

I am trying to get data from a MySQL database which I will then
populate a listbox with. Here is my current code:

'get data from database
Dim strConn As String
strConn = "Provider=MySqlProv.3.0;Data
Source=allstaffcontact;Location=localhost;User
ID=whatever;Password=whatever;Persist Security Info=False;"

Dim sql As String
sql = "SELECT * from contactdetail"

Dim da As New Data.OleDb.OleDbDataAdapter(sql, strConn)

Dim ds As New System.Data.DataSet("contactDetails")
da.Fill(ds, "contactDetails")

'fill list box
lstProspects.DataSource = ds.Tables("contactdetail")
lstProspects.DisplayMember = "lastName"

When I run the code, nothing is returned. Can someone suggest why that
might be? I was thinking that perhaps the dataset was empty, but maybe
I am doing something wrong.

TIA,
Josh
 
You got a mistake,
Dim ds As New System.Data.DataSet("contactDetails")
da.Fill(ds, "contactDetails")
it shoude be
Dim ds as new system.data.dataset("contactDetails")
da.fill("contactDetails", "whatever")
lstProspects.DataSource = ds.Tables("whatever")
lstProspects.DisplayMember = "lastName"
or
Dim ds as new system.data.dataset
da.fill(ds,"whatever")
lstProspects.DataSource = ds.Tables("whatever")
lstProspects.DisplayMember = "lastName"
or
Dim ds as new system.data.dataset
da.fill(ds)
lstProspects.DataSource = ds.Tables(0)
lstProspects.DisplayMember = "lastName"
 
Back
Top