473,404 Members | 2,195 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,404 software developers and data experts.

How to know total records selected?

Hello Group,
How can i obtain the total no of records selected with the help of
Datareader class. rowsaffected does not seem to work.

Thanks

Anand
Nov 18 '05 #1
4 1251
A DataReader reads data as your code proceeds in the reading loop. Because
of this, you can't know how much rows are returned until they are all
processed.

If you don't need the number of rows before reading them :
- count the rows in the reading loop

If you need this number before reading the rows
- issue a separate select count(*) statement to return the number of rows

(The ado.net group should be enough)

-

"anand" <an****@armour.com> a écrit dans le message de
news:uW**************@tk2msftngp13.phx.gbl...
Hello Group,
How can i obtain the total no of records selected with the help of
Datareader class. rowsaffected does not seem to work.

Thanks

Anand

Nov 18 '05 #2

"anand" <an****@armour.com> wrote in message
news:uW**************@tk2msftngp13.phx.gbl...
Hello Group,
How can i obtain the total no of records selected with the help of
Datareader class. rowsaffected does not seem to work.
Rowsafftected doesn't show you this. A reader doesn't know this number
until the processing has been done, remember that it's a streambased
mechanism. As such you'll either have to use a SELECT COUNT(*) statement
before the real sql statement or you'll have to walk through the reader
while(rdr.Read()){ i++;} The first method puts twice the stress on the db
and is really not efficient. You can also consider using an Output
parameter.

Similarly, you can get this using a dataatable using the Rows.Count
property.
Thanks

Anand


--

W.G. Ryan, eMVP

http://forums.devbuzz.com/
http://www.knowdotnet.com/williamryan.html
http://www.msmvps.com/WilliamRyan/
Nov 18 '05 #3
Thanks alot

Salute
Anand :)
"Patrice" <no****@nowhere.com> wrote in message
news:u7**************@TK2MSFTNGP11.phx.gbl...
A DataReader reads data as your code proceeds in the reading loop. Because
of this, you can't know how much rows are returned until they are all
processed.

If you don't need the number of rows before reading them :
- count the rows in the reading loop

If you need this number before reading the rows
- issue a separate select count(*) statement to return the number of rows

(The ado.net group should be enough)

-

"anand" <an****@armour.com> a écrit dans le message de
news:uW**************@tk2msftngp13.phx.gbl...
Hello Group,
How can i obtain the total no of records selected with the help of
Datareader class. rowsaffected does not seem to work.

Thanks

Anand


Nov 18 '05 #4
Thanks a lot...

Salute
Anand
"William Ryan eMVP" <do********@comcast.nospam.net> wrote in message
news:#Y**************@TK2MSFTNGP11.phx.gbl...

"anand" <an****@armour.com> wrote in message
news:uW**************@tk2msftngp13.phx.gbl...
Hello Group,
How can i obtain the total no of records selected with the help of
Datareader class. rowsaffected does not seem to work.


Rowsafftected doesn't show you this. A reader doesn't know this number
until the processing has been done, remember that it's a streambased
mechanism. As such you'll either have to use a SELECT COUNT(*) statement
before the real sql statement or you'll have to walk through the reader
while(rdr.Read()){ i++;} The first method puts twice the stress on the db
and is really not efficient. You can also consider using an Output
parameter.

Similarly, you can get this using a dataatable using the Rows.Count
property.

Thanks

Anand


--

W.G. Ryan, eMVP

http://forums.devbuzz.com/
http://www.knowdotnet.com/williamryan.html
http://www.msmvps.com/WilliamRyan/

Nov 18 '05 #5

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

Similar topics

0
by: Ellen Manning | last post by:
I've got an A2K form with a subform based on a query. This query has a checkbox and an amount field and returns records if checkbox is checked. I Dsum the amount field and display on the main...
0
by: Richard Holliingsworth | last post by:
Hello: I'm building a report to display statistics on the entire database. I have successfully built a report that groups the entire db on one field and gives me a count of db records for the...
2
by: Danny | last post by:
How to allow users to select a set of records and then let them change a field for all these records at once? I would like to do this in code on a form. I will have a form with tabular view of...
6
by: Robin S. | last post by:
**Eric and Salad - thank you both for the polite kick in the butt. I hope I've done a better job of explaining myself below. I am trying to produce a form to add products to a table (new...
1
by: Ramesh | last post by:
hi, I am selecting fields from three table for manupulating data and i want to display total number of records selected. But i am always getting -1 value, eventhough 1000 of records are selected....
3
by: Amelyan | last post by:
I need to get the total number of items/records returned into GridView. If I just do myGridView.Rows.Count, then it just returns me the total number of items on the page. But if I have, 10...
2
by: dath | last post by:
Hi, Not really a programmer here, but have been forced into the role. I was asked to develop a basic time sheet for employees to enter time. I developed the Table without a problem. I then...
2
by: sammiesue | last post by:
Hi, I have form with 2 autosummed textboxes ("total" and "casinototal"). I would like to have a grand total textbox ("grandtotal") get its value from summing "total" and "casinototal", but it...
2
by: kurtzky | last post by:
i created a form that should function as follows: i will enter a number in a textbox..then it should query from the database all the records which has that number..these records will have a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.