开发者

ADO.NET number of rows that may be returned by a SQL Server select stored procedure

In C# using ado.net, how to know just the number 开发者_运维技巧of rows that may be returned by a SQL Server select stored procedure without returning the result set and without changing the stored procedure?

I don't want to read the data at all, I only want the number of rows because the load can consume a lot of memory.


I'd originally thought that .ExecuteNonQuery() would do it. But since it doesn't work for SELECT statements, the DataReader will probably be your best (fastest) bet.

int count = 0;
using (var dr = new SqlDataReader(cmd)) {
   while (dr.Read()) count++;
}


if u just don't want to load results, create another sql procedure that just returns select Count(*) from etc...

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜