DataReader

  • Thread starter Thread starter Joseph
  • Start date Start date
J

Joseph

Good day,

How do I get the sql count result from dataReader?

I tried to use

Call connectSource()

Dim sqlstr4 As String = "Select COUNT(*) from product where product_id = " &
pid

Dim objCommand4 As New OleDb.OleDbCommand(sqlstr4, cnn)

Dim objDataReader4 As OleDb.OleDbDataReader

objDataReader4 = objCommand4.ExecuteReader

Dim total_pages As Integer = objDataReader4.Item(0)



but in vain. Kindly advise


Joseph
 
You have to loop through a DataReader to get the number of records back. In your case however, you don't need or want to return a DataReader but just use the ExecuteScalar() method on the Command object.

E.g.

Dim sqlstr4 As String = "Select COUNT(*) from product where product_id = " &pid

Dim objCommand4 As New OleDb.OleDbCommand(sqlstr4, cnn)

Dim objDataReader4 As OleDb.OleDbDataReader

Dim total_pages As Integer = CType(objCommand4.ExecuteScalar(),Integer)

Regards,
Wim Hollebrandse
http://www.wimdows.net
http://www.wimdows.com
 
Back
Top