PC Review


Reply
Thread Tools Rate Thread

Number of records in DataReader

 
 
Perre Van Wilrijk
Guest
Posts: n/a
 
      10th Sep 2004
Hello,

I want to check whether my datareader object contains rows before continuing
and binding it to my ASP datagrid. I don't have to know how many, only if
there's at least 1 row. I've found some solutions in several newsgroups but
not the solution I'm looking for.

I've seen you can use a dataset and use it's rowcount property, but I don't
want to use a dataset only to know whether there are rows returned.
I've seen another solution using two queries, the first to get the number of
rows with SQL function count(*), followed by the same query to retrieve the
data.
I've seen a third solution in which you can bind your data to a datagrid and
than check the count property of the datagrid.
I've seen a fourth solution in which you loop through the records with a
read instruction but than you've to requery because the datareader is
forward only.

So, I'm not completely pleased with those solutions and wonder if there
isn't another way. In VB6 I used to check .eof property to check whether
there were rows returned, but it seems datareader hasn't that function. Is
there another way? If not ... what solution of the four above is the best??

Thanks a lot.
--
Kind regards,
Perre Van Wilrijk,
Remove capitals to get my real email address,


 
Reply With Quote
 
 
 
 
Joyjit Mukherjee
Guest
Posts: n/a
 
      10th Sep 2004
Hi,

call the datareader's Read method in a While() loop. If it contains atleast
1 record or more, it will return true, so that you can bound it to some
control.

For counting the actual number of rows the reader contains, there's no way
out as there are only 1 row in the memory of the reader at a time. Maybe
while looping through the while loop, using a counter you can get that.

HTH
Regards
Joyjit

"Perre Van Wilrijk" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello,
>
> I want to check whether my datareader object contains rows before

continuing
> and binding it to my ASP datagrid. I don't have to know how many, only if
> there's at least 1 row. I've found some solutions in several newsgroups

but
> not the solution I'm looking for.
>
> I've seen you can use a dataset and use it's rowcount property, but I

don't
> want to use a dataset only to know whether there are rows returned.
> I've seen another solution using two queries, the first to get the number

of
> rows with SQL function count(*), followed by the same query to retrieve

the
> data.
> I've seen a third solution in which you can bind your data to a datagrid

and
> than check the count property of the datagrid.
> I've seen a fourth solution in which you loop through the records with a
> read instruction but than you've to requery because the datareader is
> forward only.
>
> So, I'm not completely pleased with those solutions and wonder if there
> isn't another way. In VB6 I used to check .eof property to check whether
> there were rows returned, but it seems datareader hasn't that function.

Is
> there another way? If not ... what solution of the four above is the

best??
>
> Thanks a lot.
> --
> Kind regards,
> Perre Van Wilrijk,
> Remove capitals to get my real email address,
>
>



 
Reply With Quote
 
http://www.visual-basic-data-mining.net/forum
Guest
Posts: n/a
 
      11th Sep 2004
In .NET Framework 1.1, the DataReader has a Has Rows property.

If (DataReader.HasRows)
---do something

--
forum member
http://www.visual-basic-data-mining.net/forum


"Perre Van Wilrijk" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello,
>
> I want to check whether my datareader object contains rows before

continuing
> and binding it to my ASP datagrid. I don't have to know how many, only if
> there's at least 1 row. I've found some solutions in several newsgroups

but
> not the solution I'm looking for.
>
> I've seen you can use a dataset and use it's rowcount property, but I

don't
> want to use a dataset only to know whether there are rows returned.
> I've seen another solution using two queries, the first to get the number

of
> rows with SQL function count(*), followed by the same query to retrieve

the
> data.
> I've seen a third solution in which you can bind your data to a datagrid

and
> than check the count property of the datagrid.
> I've seen a fourth solution in which you loop through the records with a
> read instruction but than you've to requery because the datareader is
> forward only.
>
> So, I'm not completely pleased with those solutions and wonder if there
> isn't another way. In VB6 I used to check .eof property to check whether
> there were rows returned, but it seems datareader hasn't that function.

Is
> there another way? If not ... what solution of the four above is the

best??
>
> Thanks a lot.
> --
> Kind regards,
> Perre Van Wilrijk,
> Remove capitals to get my real email address,
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
fetching records using datareader and updation nasirmajor@yahoo.com Microsoft ASP .NET 1 10th Jul 2006 02:35 PM
DataReader skips records?? =?Utf-8?B?TU4=?= Microsoft ADO .NET 7 23rd Nov 2004 05:51 PM
datareader - how many records. robert batt Microsoft Dot NET Framework Forms 2 11th Oct 2003 01:54 AM
records returned from datareader error Davef Microsoft ASP .NET 1 28th Aug 2003 05:40 AM
Re: Can Locate records with datareader Kathleen Dollard Microsoft ADO .NET 0 6th Aug 2003 04:20 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:39 PM.