No RecordCount property exists to indicate how many records are being fetched when you use the OleDbDataReader or SqlDataReader class in Visual C# (308352)
The information in this article applies to:
- Microsoft ADO.Net 2.0
- Microsoft ADO.NET (included with the .NET Framework) 1.0
- Microsoft Visual C# .NET (2002)
- Microsoft Visual C# .NET (2003)
- Microsoft Visual C# 2005
This article was previously published under Q308352
For a Microsoft Visual Basic .NET version of this article, see 308050.
This article refers to the following Microsoft .NET Framework Class Library namespaces:
- System.Data
- System.Data.SqlClient
SYMPTOMS
When you use the OleDbDataReader or SqlDataReader class, no RecordCount property exists to indicate how many records are being fetched.
CAUSE
The DataReader object or the back-end data source does not typically know how many records are being fetched until the last record is sent to the client.
Even an ActiveX Data Objects (ADO) Recordset returns -1 for the RecordCount property when it uses a forward-only cursor to retrieve data. DataReader exhibits similar behavior because it uses a forward-only cursor to retrieve rows and columns.
RESOLUTION
To work around this problem, use one of the following methods:
- Count the records as you go through the reader.
- Run a SELECT COUNT(*) query first. Note that this query may be out of date by the time you finish reading the data.
STATUSThis behavior is by design.REFERENCES
For more information, click the following article number to view the article in the Microsoft Knowledge Base:
194973
ADO: Recordcount may return -1
Modification Type: | Minor | Last Reviewed: | 10/4/2006 |
---|
Keywords: | kbtshoot kbnofix kbprb kbSqlClient kbSystemData KB308352 kbAudDeveloper |
---|
|