IDataReader - Any way to get the total rows?

Well past the date posted but there is a way, that worked for me took a while to get because i suck at wording my google searches.

dbCommand.Connection.Open();
//dbReader = dbCommand.ExecuteReader();  I left this here to show not to do the read

searchCount = dbCommand.ExecuteScalar(); // this line returns the value count
                                         // from my tests on my reader it works perfectly

No, the datareader will not return a count first. However, if you do need to do it, use two queries that return multiple result sets.

for example in SQL Server:

sql = "SELECT COUNT(1) FROM A; SELECT * FROM A;"

Iterate the result sets. Use the IDataReader on the second result set.

The database server should be able to do this quite fast if it is using appropriate indexes.


No.

IDataReader is a simple forward-only view of a resultset; it cannot get a count.