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...
精彩评论