is it possible to find row count of a table using data reader?
is it possible开发者_开发技巧 to find row count of a table using data reader?
If you need the count of sth write a different query such as select count(*) from ??
and execute the ExecuteScalar()
on it instead of ExecuteReader()
No direct property that you could use. You should be able to iterate through it and count rows:
Int32 rowCount = 0;
while (reader.Read()) rowCount++;
I would not recommend it though. Its a waste for something a single query with a single result could do.
DataReader normally fetches the row upon calling .Read() method. It doesn't have any information on the number of rows in the underlying result set until it reaches the last row.
精彩评论