HasRows

  • Thread starter Thread starter Rick
  • Start date Start date
R

Rick

I have found the HasRows member of the OleDbConnection. This is very nice to
tell me if I have any data coming but what if I want to see how many rows of
data I have. Is there a similar member to Recordcount?

Thanks for your help in advance!!!
 
I have found the HasRows member of the OleDbConnection.

The OleDbConnection object doesn't have a HasRows member:
http://authors.aspalliance.com/aspxtreme/sys/data/oledb/OleDbConnectionClass.aspx

You're confusing it with the OleDbReader class:
http://msdn2.microsoft.com/en-us/library/system.data.oledb.oledbdatareader.hasrows.aspx
This is very nice to tell me if I have any data coming but what if I want
to see how many rows of data I have. Is there a similar member to
Recordcount?

No. If you need to know the actual number of records contained in the
OleDbReader, as opposed to whether there are any records or not, you have
several options:

1) Don't use an OleDbReader - use a DataSet instead, and interrogate the
<DataSet.Tables[0].Rows.Count property.

2) Have your OleDbReader return two Resultsets, the first which contains a
scalar of the number of rows contained in the second. Interrogate the first
one, then invoke the NextResult method to advance to the second:
http://msdn2.microsoft.com/en-us/library/system.data.oledb.oledbdatareader.nextresult.aspx

E.g.

SELECT COUNT(*) FROM <Table>
SELECT (*) FROM <Table>

3) Read your OleDbReader object into another object e.g. a generic
collection and then interrogate that, or increment a counter as you are
iterating through it.
 
Back
Top