开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜