When using the
OleDbDataReader or
SqlDataReader class, there is no
RecordCount property to tell how many records are being fetched.
Back to the top
The
DataReader object (or even the back-end data source) doesn't typically know how many records are being fetched until the last one is sent to the client. Even an ActiveX Data Objects (ADO) Recordset returns -1 for
RecordCount when retrieving data using a forward-only cursor.
DataReader exhibits similar behavior because it uses a forward-only cursor for retrieving rows and columns.
Back to the top
You can work around this problem in the following ways:
| • | Count the records as you go through the reader. |
| • | Run a SELECT COUNT(*) query first (although this may be out of date by the time you finish reading data). |
Back to the top
This behavior is by design.
Back to the top
For additional information, click the article number below
to view the article in the Microsoft Knowledge Base:
194973 (http://support.microsoft.com/kb/194973/EN-US/) PRB: ADO: Recordcount May Return -1
Back to the top