473,287 Members | 1,560 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

DataReader

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
Nov 17 '05 #1
4 1766
What I want is the number of records in the product table.....
"Joseph" <ve******@starhub.net.sg> wrote in message
news:Om**************@TK2MSFTNGP11.phx.gbl...
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

Nov 17 '05 #2
What I want is the number of records in the product table.....
"Joseph" <ve******@starhub.net.sg> wrote in message
news:Om**************@TK2MSFTNGP11.phx.gbl...
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

Nov 17 '05 #3
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

---
Posted using Wimdows.net Newsgroups - http://www.wimdows.net/newsgroups/
Nov 17 '05 #4
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

---
Posted using Wimdows.net Newsgroups - http://www.wimdows.net/newsgroups/
Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Yasutaka Ito | last post by:
Hi, My friend had a little confusion about the working of DataReader after reading an article from MSDN. Following is a message from him... <!-- Message starts --> I was going thru DataReader...
6
by: Ravi | last post by:
Hi, I am not able to understand why a datareader needs a connection to the DB all the time. Here is what I tried. Sqlcommand cmd = ("select * from table1",con) // where con is the connection...
5
by: Jason Huang | last post by:
Hi, Is it possible to bind DataReader to a DataGrid in C# windows form? And how? And can we update data in a DataSet by using the DataReader? Thanks for help. Jason
12
by: Thomas Scheiderich | last post by:
I have 2 dropdowns that are exactly the same and I don't want to re-read for each. Is there a way to do something like below where I read the data, bind to depCity1 and then bind to destCity2. ...
20
by: Mark | last post by:
Hi all, quick question , a DataView is memory resident "view" of data in a data table therefore once populated you can close the connection to the database. Garbage collection can then be used to...
2
by: Andrei Pociu | last post by:
In a typical ASP .NET Web Application (website), I'm currently using a class where I declare some public static objects. For example there's the place where I initialize the SqlConnection. Also...
1
by: Brent | last post by:
I'm having a hard time wrapping my head around how to build a multi-dimensional array of n length out of a DataReader loop. Take this pseudo-code: ======================================= public...
7
by: Varangian | last post by:
Hi all, the question I want to ask if the conversion of a DataReader to a Table looping through the DataReader is better than using the Fill Method of the DataAdapter... I'm asking because...
7
by: Diffident | last post by:
Hello All, I would like to use DataReader based accessing in my Data Access Layer (DAL). What is considered to be a best practice while returning from a DAL method that executes a query and...
3
by: Johnny Jörgensen | last post by:
I've got an error that I simply cannot locate: I've got a form in which I use a datareader object to read information from a db. After the read, I close the reader and I dispose of both the...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.