471,325 Members | 1,539 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,325 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 7354
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Mark | last post: by
6 posts views Thread by BuddyWork | last post: by
reply views Thread by BuddyWork | last post: by
5 posts views Thread by Robert Bravery | last post: by
1 post views Thread by fniles | last post: by
reply views Thread by rosydwin | last post: by

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.