473,395 Members | 1,676 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,395 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 1770
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.