DataReader

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
 
W

Wim Hollebrandse

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,810
Latest member
Kassie0918

Latest Threads

Top