SQL - 获取返回的结果集的行数 [英] SQL - Get the row count of the resultset returned

查看:842
本文介绍了SQL - 获取返回的结果集的行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

如何获取select语句返回的结果集的行数?我想要结果集和计数。

Hello,
How do you get the row count of the resultset returned from a select statement? I want both the resultset and the count.

推荐答案

取决于你如何阅读结果。如果您正在使用SqlDataReader,那么您必须遍历每一行并在从读取器处理它们时手动计算它们 - SqlDataReader没有行计数,因为它不会一次读取所有记录所以它不知道在读到最后一个之前有多少个。



如果您使用DataAdapter和DataSet或DataTable,那么您可以填充它并使用DataTable.Rows.Count任何时候的财产。
Depends on how you are reading the results. If you are using the SqlDataReader, then you have to iterate through each row and count them manually as you process them from the reader - SqlDataReader has no row count, as it doesn't read all the records at once so it doesn't know how manythere are until it's read the last one.

If you use a DataAdapter and a DataSet or DataTable, then your can fill it and use the DataTable.Rows.Count property at any time.


这篇关于SQL - 获取返回的结果集的行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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