ExecuteReader

  • Thread starter Thread starter Roy Gourgi
  • Start date Start date
R

Roy Gourgi

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
 
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.
 
Hi Roy,

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

Thi
 
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 said:
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]
- (e-mail address removed)

Roy Gourgi said:
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
 
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 said:
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 said:
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]
- (e-mail address removed)

Roy Gourgi said:
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
 
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 ) said:
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 said:
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 said:
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]
- (e-mail address removed)

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
 
Hi,

Roy Gourgi said:
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,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top