Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Having a problem counting number of record from mySql database:
SQL
adpter = New MySqlDataAdapter("select count(*) from bookings where busNumber = '" & txtBusNumber.Text & "' and departTime = '" & cmbDepartTime.Text & "' and departDay = '" & cmbDay.Text & "'", con)
        Dim myDataSet = New DataSet
        adpter.Fill(myDataSet, "bookings")
        

        txtCount.Text = myDataSet.Tables("bookings").Rows(0).Item(0)

I get 0...

please Help
Posted
Updated 4-Oct-12 6:11am
v2

1 solution

Check your database and see, if you really have any records for the filter criteria you set. From the query, it is clear that you have all the filter fields as varchar, so the query seems okay.

Some optimization point,
You better use parameterized query. This is not a must requirement but always advisable.

I see, you use a dataset to get the count value. This will take more resource. So, I suggest, you use ExecuteScalar.

cheers
 
Share this answer
 
v2
Comments
ridoy 4-Oct-12 16:13pm    
+5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900