How do I get the number of rows a datareader has? I can tell HasRows, but
not how many.
Thanks. 6 8459
you need to read read to the end with a counter.
a datareader (at least for sqlserver) is a forward only cursor returning
data from the response stream buffer. thus you can not lnow how many rows
there are until you read to the end. on a big query you can read rows while
the server is still performing the query.
this is also why you can not read return paramater from a sp until you've
read all the result sets.
-- bruce (sqlwork.com)
"dew" <de*@yahoo.com> wrote in message
news:uN**************@TK2MSFTNGP09.phx.gbl... How do I get the number of rows a datareader has? I can tell HasRows, but not how many.
Thanks.
Hello dew,
No way other than iterating through the reader. Sometimes the overhead of
doing this is so much that I have seen people running a count query too,
before/after Read() ing the data, if needed.
You might want to post this question in microsoft.public.dotnet.framework.adonet.
HTH,
r. How do I get the number of rows a datareader has? I can tell HasRows, but not how many.
Thanks.
Thanks, all, I guess I'll have to use a dataset.
"dew" <de*@yahoo.com> wrote in message
news:uN**************@TK2MSFTNGP09.phx.gbl... How do I get the number of rows a datareader has? I can tell HasRows, but not how many.
Thanks.
As one poster has already, commented, you can still use a DataReader. Just
populate it with 2 resultsets, the first one being the count of rows returns.
then use the DataReader's NextResultSet() method to switch to the one
containing all the rows.
Peter
--
Co-founder, Eggheadcafe.com developer portal: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
"dew" wrote: How do I get the number of rows a datareader has? I can tell HasRows, but not how many.
Thanks.
this is really a bad pattern. it requires running the query twice, and if a
row is inserted/deleted between queries, the wrong answer can appear. to
make the query stable you have to use exclusive lock, or select into a temp
table.
-- bruce (sqlwork.com)
"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.com> wrote in message
news:0A**********************************@microsof t.com... As one poster has already, commented, you can still use a DataReader. Just populate it with 2 resultsets, the first one being the count of rows returns. then use the DataReader's NextResultSet() method to switch to the one containing all the rows. Peter
-- Co-founder, Eggheadcafe.com developer portal: http://www.eggheadcafe.com UnBlog: http://petesbloggerama.blogspot.com
"dew" wrote:
How do I get the number of rows a datareader has? I can tell HasRows, but not how many.
Thanks.
Good point, Bruce, if that precision is critical to the business logic
scenario.
But then, doing so would make it a "good pattern"?
Cheers,
Peter
--
Co-founder, Eggheadcafe.com developer portal: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
"Bruce Barker" wrote: this is really a bad pattern. it requires running the query twice, and if a row is inserted/deleted between queries, the wrong answer can appear. to make the query stable you have to use exclusive lock, or select into a temp table.
-- bruce (sqlwork.com)
"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.com> wrote in message news:0A**********************************@microsof t.com... As one poster has already, commented, you can still use a DataReader. Just populate it with 2 resultsets, the first one being the count of rows returns. then use the DataReader's NextResultSet() method to switch to the one containing all the rows. Peter
-- Co-founder, Eggheadcafe.com developer portal: http://www.eggheadcafe.com UnBlog: http://petesbloggerama.blogspot.com
"dew" wrote:
How do I get the number of rows a datareader has? I can tell HasRows, but not how many.
Thanks. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Claudia Fong |
last post by:
Hi,
I'm using a DataReader to connect to a db and retrieve data from the db.
I just wondering how can I know the numbers of rows contain in my DB for
the sql statement I used? For example, if...
|
by: Jacko |
last post by:
Hi guys,
Say I made a SELECT statement to my sql DB that would return 50 rows
that I will use a sqldatareader to access. Instead of iterating through
each and every row of the datareader, I'd...
|
by: Andrew |
last post by:
Hey all,
Have a strange one here, and being still fairly new to .NET isn't helping me
understand it.
I am having a problem where a DataReader doesn't return all the rows when I
try to use a...
|
by: Chris Tremblay |
last post by:
I am trying to figure out how to go about retrieving the number of results
returned from my queries in SQL server from VB.NET without using a the
Select Count(*) query. The method that I was using...
|
by: ae |
last post by:
My datareader looks like this where dtrItemList is the datareader and
chklExceptionList is my checkboxlist. the rows come in just fine, but I need
help also including the name of the columns for...
|
by: Mattyw |
last post by:
Hi
I have a sqlcommand that returns all the rows in a column and then pass
that to a datareader.
I am new to VS.Net and so far I can only return the first row in the
first column using
...
|
by: hazz |
last post by:
The datareader below contains two rows of two columns but in the for loop,
the values for only the first row are getting printed twice. How do I get to
the values of the second row? Thanks. -hazz...
|
by: trint |
last post by:
I have a select statement that all I want to do is get the number of
rows returned in my query:
string strSQLAccountInfo1 = "select * " +
"FROM orders " +
"where user_id = '" +...
|
by: Andy B |
last post by:
How would you find out if a linq table has 0 rows in it? I have this code:
NewsContext.V_News() '*** linq table to be tested for 0 rows
Any ideas?
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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...
|
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,...
|
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...
|
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...
| |