SQL Server选择存储过程可能返回的ADO.NET行数 [英] ADO.NET number of rows that may be returned by a SQL Server select stored procedure

查看:77
本文介绍了SQL Server选择存储过程可能返回的ADO.NET行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用ado.net的C#中,如何仅知道SQL Server选择存储过程可能返回的行数,而不返回结果集和不更改存储过程?

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.

推荐答案

我本来以为.ExecuteNonQuery()可以做到。但是,由于它不适用于SELECT语句,因此DataReader可能是您最好(最快)的选择。

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++;
}

这篇关于SQL Server选择存储过程可能返回的ADO.NET行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆