PC Review


Reply
Thread Tools Rate Thread

DbDataReader numRows?

 
 
=?Utf-8?B?RGF2aWQgVGhpZWxlbg==?=
Guest
Posts: n/a
 
      4th Nov 2005
Hi;

Is there a way to get the number of rows a DbDataReader has?

--
thanks - dave
 
Reply With Quote
 
 
 
 
Kevin Yu [MSFT]
Guest
Posts: n/a
 
      5th Nov 2005
Hi dave

As far as I know, we cannot get the row count for a DataReader. Because
when you open the data reader, a cursor is open the on the server, it
doesn't provide the row count information. You can try to use COUNT in the
SQL statement to get the row count first.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

 
Reply With Quote
 
=?Utf-8?B?RGF2aWQgVGhpZWxlbg==?=
Guest
Posts: n/a
 
      5th Nov 2005
Hi;

That's what I figured but it never hurts to ask. I can't do a count because
I don't control the select.

Oh well, just makes my coding a little harder.

--
thanks - dave


"Kevin Yu [MSFT]" wrote:

> Hi dave
>
> As far as I know, we cannot get the row count for a DataReader. Because
> when you open the data reader, a cursor is open the on the server, it
> doesn't provide the row count information. You can try to use COUNT in the
> SQL statement to get the row count first.
>
> Kevin Yu
> =======
> "This posting is provided "AS IS" with no warranties, and confers no
> rights."
>
>

 
Reply With Quote
 
CT
Guest
Posts: n/a
 
      5th Nov 2005
You can use the HasRows proeprty to check if there are any more rows. It
might not be what you want, but you can do this without movinf the cursor,
which is what the Read method does.

--
Carsten Thomsen
Communities - http://community.integratedsolutions.dk

"David Thielen" <(E-Mail Removed)> wrote in message
news:5639901C-363D-436D-807E-(E-Mail Removed)...
> Hi;
>
> That's what I figured but it never hurts to ask. I can't do a count
> because
> I don't control the select.
>
> Oh well, just makes my coding a little harder.
>
> --
> thanks - dave
>
>
> "Kevin Yu [MSFT]" wrote:
>
>> Hi dave
>>
>> As far as I know, we cannot get the row count for a DataReader. Because
>> when you open the data reader, a cursor is open the on the server, it
>> doesn't provide the row count information. You can try to use COUNT in
>> the
>> SQL statement to get the row count first.
>>
>> Kevin Yu
>> =======
>> "This posting is provided "AS IS" with no warranties, and confers no
>> rights."
>>
>>



 
Reply With Quote
 
=?Utf-8?B?RGF2aWQgVGhpZWxlbg==?=
Guest
Posts: n/a
 
      5th Nov 2005
The way I read the docs for HasRows is it tells you if you have any from the
select, but not if you have any more? Are you sure this works for all
DbConnection drivers?

--
thanks - dave


"CT" wrote:

> You can use the HasRows proeprty to check if there are any more rows. It
> might not be what you want, but you can do this without movinf the cursor,
> which is what the Read method does.
>
> --
> Carsten Thomsen
> Communities - http://community.integratedsolutions.dk
>
> "David Thielen" <(E-Mail Removed)> wrote in message
> news:5639901C-363D-436D-807E-(E-Mail Removed)...
> > Hi;
> >
> > That's what I figured but it never hurts to ask. I can't do a count
> > because
> > I don't control the select.
> >
> > Oh well, just makes my coding a little harder.
> >
> > --
> > thanks - dave
> >
> >
> > "Kevin Yu [MSFT]" wrote:
> >
> >> Hi dave
> >>
> >> As far as I know, we cannot get the row count for a DataReader. Because
> >> when you open the data reader, a cursor is open the on the server, it
> >> doesn't provide the row count information. You can try to use COUNT in
> >> the
> >> SQL statement to get the row count first.
> >>
> >> Kevin Yu
> >> =======
> >> "This posting is provided "AS IS" with no warranties, and confers no
> >> rights."
> >>
> >>

>
>
>

 
Reply With Quote
 
CT
Guest
Posts: n/a
 
      6th Nov 2005
Correct, it will only tell you if there is one ir more rows in the
DataReader. It is generally used before trying to use the Read method to
check if there are any rows. I suppose that you could do a ExecuteScalar to
get the count along these lines:

Dim rowCount As Integer
Dim rowCountSQL As String = "SELECT COUNT(*) FROM tablename"

Dim yourConnection As New SqlConnection("...")
Dim yourCommand As New SqlCommand(rowCountSQL)

rowCount = CInt(yourCommand.ExecuteScalar())


--
Carsten Thomsen
Communities - http://community.integratedsolutions.dk

"David Thielen" <(E-Mail Removed)> wrote in message
news:2DC0EE25-DC8E-4FC5-B331-(E-Mail Removed)...
> The way I read the docs for HasRows is it tells you if you have any from
> the
> select, but not if you have any more? Are you sure this works for all
> DbConnection drivers?
>
> --
> thanks - dave
>
>
> "CT" wrote:
>
>> You can use the HasRows proeprty to check if there are any more rows. It
>> might not be what you want, but you can do this without movinf the
>> cursor,
>> which is what the Read method does.
>>
>> --
>> Carsten Thomsen
>> Communities - http://community.integratedsolutions.dk
>>
>> "David Thielen" <(E-Mail Removed)> wrote in message
>> news:5639901C-363D-436D-807E-(E-Mail Removed)...
>> > Hi;
>> >
>> > That's what I figured but it never hurts to ask. I can't do a count
>> > because
>> > I don't control the select.
>> >
>> > Oh well, just makes my coding a little harder.
>> >
>> > --
>> > thanks - dave
>> >
>> >
>> > "Kevin Yu [MSFT]" wrote:
>> >
>> >> Hi dave
>> >>
>> >> As far as I know, we cannot get the row count for a DataReader.
>> >> Because
>> >> when you open the data reader, a cursor is open the on the server, it
>> >> doesn't provide the row count information. You can try to use COUNT in
>> >> the
>> >> SQL statement to get the row count first.
>> >>
>> >> Kevin Yu
>> >> =======
>> >> "This posting is provided "AS IS" with no warranties, and confers no
>> >> rights."
>> >>
>> >>

>>
>>
>>



 
Reply With Quote
 
CT
Guest
Posts: n/a
 
      6th Nov 2005
I should add that if there frequent changes to the number of rows in the
table(s) you select from, the retrieved row count might not match the
actualumber of rows in the DataReader.

--
Carsten Thomsen
Communities - http://community.integratedsolutions.dk

"CT" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Correct, it will only tell you if there is one ir more rows in the
> DataReader. It is generally used before trying to use the Read method to
> check if there are any rows. I suppose that you could do a ExecuteScalar
> to get the count along these lines:
>
> Dim rowCount As Integer
> Dim rowCountSQL As String = "SELECT COUNT(*) FROM tablename"
>
> Dim yourConnection As New SqlConnection("...")
> Dim yourCommand As New SqlCommand(rowCountSQL)
>
> rowCount = CInt(yourCommand.ExecuteScalar())
>
>
> --
> Carsten Thomsen
> Communities - http://community.integratedsolutions.dk
>
> "David Thielen" <(E-Mail Removed)> wrote in message
> news:2DC0EE25-DC8E-4FC5-B331-(E-Mail Removed)...
>> The way I read the docs for HasRows is it tells you if you have any from
>> the
>> select, but not if you have any more? Are you sure this works for all
>> DbConnection drivers?
>>
>> --
>> thanks - dave
>>
>>
>> "CT" wrote:
>>
>>> You can use the HasRows proeprty to check if there are any more rows. It
>>> might not be what you want, but you can do this without movinf the
>>> cursor,
>>> which is what the Read method does.
>>>
>>> --
>>> Carsten Thomsen
>>> Communities - http://community.integratedsolutions.dk
>>>
>>> "David Thielen" <(E-Mail Removed)> wrote in message
>>> news:5639901C-363D-436D-807E-(E-Mail Removed)...
>>> > Hi;
>>> >
>>> > That's what I figured but it never hurts to ask. I can't do a count
>>> > because
>>> > I don't control the select.
>>> >
>>> > Oh well, just makes my coding a little harder.
>>> >
>>> > --
>>> > thanks - dave
>>> >
>>> >
>>> > "Kevin Yu [MSFT]" wrote:
>>> >
>>> >> Hi dave
>>> >>
>>> >> As far as I know, we cannot get the row count for a DataReader.
>>> >> Because
>>> >> when you open the data reader, a cursor is open the on the server, it
>>> >> doesn't provide the row count information. You can try to use COUNT
>>> >> in
>>> >> the
>>> >> SQL statement to get the row count first.
>>> >>
>>> >> Kevin Yu
>>> >> =======
>>> >> "This posting is provided "AS IS" with no warranties, and confers no
>>> >> rights."
>>> >>
>>> >>
>>>
>>>
>>>

>
>



 
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
dbDataReader Mr. X. Microsoft C# .NET 5 25th Sep 2010 01:34 AM
DbDataReader.HasRows - Whose Idea was that? Jehu Galeahsa Microsoft C# .NET 1 29th May 2010 01:57 AM
DbConnection, DbDataReader and DbCommand Jelle de Jong Microsoft C# .NET 2 11th Mar 2008 02:10 AM
DbDataReader.Read() result =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?= Microsoft ADO .NET 2 5th Nov 2005 01:29 PM
DbDataReader.previous() =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?= Microsoft ADO .NET 3 4th Nov 2005 05:45 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:03 AM.