Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I get the number of records in a DataReader?

Status
Not open for further replies.

qwert231

Programmer
Sep 4, 2001
756
US
I would like to do this before I start reading the records. The RecordsAffected property is not set until all rows are read and you close the OleDbDataReader.

So, what can I do? Is there a way to do it?
 
The datareader has a property called RecordsAffected.
That is equal of the row count in a select sql statement.

hth Daren J. Lahey
Just another computer guy...
 
I would like to do this before I start reading the records.

The RecordsAffected property is not set until all rows are read and you close the OleDbDataReader.

So, what can I do? Is there a way to do it?
 
Before you execute the command to the DataReader, you can have this code:

int iRecordsAffected;
iRecordsAffected = command1.ExecuteNonQuery();

will give you the number of rows of a select sql statement


Daren J. Lahey
Just another computer guy...
 
Not that I know of. I think this has to do with the fact that the reader to my knowledge doesn't get anything till the .read command. At which point it retrieves the data in a stream like format. This is what I have gotten out of the documentation anyway. That'l do donkey, that'l do
[bravo] Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top