473,383 Members | 1,978 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,383 software developers and data experts.

ExecuteReader

Hi,

Is there a way to get the number of rows that the ExecuteReader has fetched
without iterating through with the Read(). I tried RecordsAffected but that
returns -1 all the time. HasRows only tells you that there is 1 or more
rows, but it does not tell you how many.

TIA
Roy
Dec 6 '05 #1
7 7430
Roy,

No, there is not. The reader typically will not know how many rows are
returned. You either have to include it as a part of the query (have a
column with the count, but that is not efficient), or count the number of
iterations.

You could also issue a second, separate select with the same parameters,
but that introduces extra, undesirable overhead.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Roy Gourgi" <ro***@videotron.ca> wrote in message
news:L1*****************@wagner.videotron.net...
Hi,

Is there a way to get the number of rows that the ExecuteReader has
fetched without iterating through with the Read(). I tried RecordsAffected
but that returns -1 all the time. HasRows only tells you that there is 1
or more rows, but it does not tell you how many.

TIA
Roy

Dec 6 '05 #2
Hi Roy,

One possible way is using batch SQL statements, first statement to
count. Use DataReader.NextResult to advance to the next result.

Thi

Dec 6 '05 #3
Thanks Nicholas,

As it turns out I had to process the info in the datareader so counting the
number of iterations is the way to go for my problem.

Funny though, in Visual FoxPro you could do everything I am asking for
without a sweat. I am wondering why they did not transport this to VS.

Thanks
Roy

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:%2*****************@TK2MSFTNGP10.phx.gbl...
Roy,

No, there is not. The reader typically will not know how many rows are
returned. You either have to include it as a part of the query (have a
column with the count, but that is not efficient), or count the number of
iterations.

You could also issue a second, separate select with the same
parameters, but that introduces extra, undesirable overhead.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Roy Gourgi" <ro***@videotron.ca> wrote in message
news:L1*****************@wagner.videotron.net...
Hi,

Is there a way to get the number of rows that the ExecuteReader has
fetched without iterating through with the Read(). I tried
RecordsAffected but that returns -1 all the time. HasRows only tells you
that there is 1 or more rows, but it does not tell you how many.

TIA
Roy


Dec 6 '05 #4
Thanks Truong, for now I think I will use the iterations method.

Roy

"Truong Hong Thi" <th*****@gmail.com> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...
Hi Roy,

One possible way is using batch SQL statements, first statement to
count. Use DataReader.NextResult to advance to the next result.

Thi

Dec 6 '05 #5
Hi,

This is not a limitation of VS, not even .NET . It's the way SQL server
serve a server side cursor.

BTW, the very same thing apply to output and return parameters.
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Roy Gourgi" <ro***@videotron.ca> wrote in message
news:oQ*****************@wagner.videotron.net...
Thanks Nicholas,

As it turns out I had to process the info in the datareader so counting
the number of iterations is the way to go for my problem.

Funny though, in Visual FoxPro you could do everything I am asking for
without a sweat. I am wondering why they did not transport this to VS.

Thanks
Roy

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in message news:%2*****************@TK2MSFTNGP10.phx.gbl...
Roy,

No, there is not. The reader typically will not know how many rows
are returned. You either have to include it as a part of the query (have
a column with the count, but that is not efficient), or count the number
of iterations.

You could also issue a second, separate select with the same
parameters, but that introduces extra, undesirable overhead.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Roy Gourgi" <ro***@videotron.ca> wrote in message
news:L1*****************@wagner.videotron.net...
Hi,

Is there a way to get the number of rows that the ExecuteReader has
fetched without iterating through with the Read(). I tried
RecordsAffected but that returns -1 all the time. HasRows only tells you
that there is 1 or more rows, but it does not tell you how many.

TIA
Roy



Dec 6 '05 #6
Hi Ignacio,

Who makes SQL? I thought that it was Microsoft!

What do you mean when you say that the same applies to output and return
parameters?

Roy

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:O3***************@TK2MSFTNGP09.phx.gbl...
Hi,

This is not a limitation of VS, not even .NET . It's the way SQL server
serve a server side cursor.

BTW, the very same thing apply to output and return parameters.
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Roy Gourgi" <ro***@videotron.ca> wrote in message
news:oQ*****************@wagner.videotron.net...
Thanks Nicholas,

As it turns out I had to process the info in the datareader so counting
the number of iterations is the way to go for my problem.

Funny though, in Visual FoxPro you could do everything I am asking for
without a sweat. I am wondering why they did not transport this to VS.

Thanks
Roy

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in message news:%2*****************@TK2MSFTNGP10.phx.gbl...
Roy,

No, there is not. The reader typically will not know how many rows
are returned. You either have to include it as a part of the query
(have a column with the count, but that is not efficient), or count the
number of iterations.

You could also issue a second, separate select with the same
parameters, but that introduces extra, undesirable overhead.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Roy Gourgi" <ro***@videotron.ca> wrote in message
news:L1*****************@wagner.videotron.net...
Hi,

Is there a way to get the number of rows that the ExecuteReader has
fetched without iterating through with the Read(). I tried
RecordsAffected but that returns -1 all the time. HasRows only tells
you that there is 1 or more rows, but it does not tell you how many.

TIA
Roy



Dec 6 '05 #7
Hi,

"Roy Gourgi" <ro***@videotron.ca> wrote in message
news:b0******************@wagner.videotron.net...

Who makes SQL? I thought that it was Microsoft!
Well, last time I checked that was true :) , so what?
What do you mean when you say that the same applies to output and return
parameters?

That you do not have access to them until you end iterating in the returned
rows, I know it was not in the original thread (any mention to output
params ) I mixed two posts I was reading/answering at the same time.
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Dec 6 '05 #8

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

Similar topics

0
by: James Hokes | last post by:
Hi All, We're using the 1.1. Framework against SQL Server 2000, and are having a strange issue where we don't get errors back from the stored procedure, i.e. the exception never gets thrown. ...
1
by: Mark | last post by:
It appears that you can only retrieve an Output parameter from a SQL Server stored procedure when using the ExecuteNonQuery of the SqlCommand class, and cannot use the ExecuteReader() method. In...
6
by: BuddyWork | last post by:
Does anyone know if there are any articles explaining how I could debug into SqlCommand.ExecuteReader so I can see why I am getting a particular error. thanks
0
by: BuddyWork | last post by:
Hello, The problem is that when using SqlCommand.ExecuteReader and the SQL statement raises an error of severity of 16 then ExecuteReader throws an exception, when you use...
5
by: orencs | last post by:
Hello, I am using Microsoft.Practices.EnterpriseLibrary.Data. I am running the following sqlCommand = "SELECT var1 FROM table1 WHERE var2 IN (4,5,6) ; SELECT var3 FROM table2 WHERE var2 IN...
2
by: MattB | last post by:
I'm trying to implement an example I found for displaying images stored in a SQL database. The example code looks like this (in page_load): Dim connstr As String = "Integrated...
4
by: phil | last post by:
Hi, With the code below, i get the error: ExecuteReader: Connection property has not been initialized. Description: An unhandled exception occurred during the execution of the current web...
5
by: Robert Bravery | last post by:
HI all, Whats the differe between useing Executereader() and Beginexecutereader()...endexecutereader() for asyncronys running of a SP Thanks Robert
1
by: fniles | last post by:
I am using OLEDBDataReader to read from an Access database. I have 4 data source where I get my data from, and each data source is in its own thread. When receiving data, if it is a new...
7
by: fniles | last post by:
I am using VB.Net 2003 and MS Access (connecting using OleDBConnection). I read using DataAdapter and DataSet, not DataReader. When many people try to access the database at the same time, I get...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
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...
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...

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.