Since DataReader is a forward only sequential reader you can't determine the
number of results until you have read through them all (when Read returns
false).
Instead you can issue a "select count(fieldname) from tablename where..."
query which can be used to get the number of items matching your query, call
the ExecuteScalar method to return this single result.
You can alternatively use a DataAdapter which will fill a DataSet with the
results and you can query the number of rows contained, but for a large
quantity of records this can be resource intensive.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.