473,398 Members | 2,088 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,398 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 7433
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...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
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
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
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.