开发者

How can I count the number of rows returned by a MySQL Query?

开发者 https://www.devze.com 2023-03-06 07:43 出处:网络
Is there an easier way of doing this besides loading the data into a DataTable and using Rows.Count or using a MySqlDataR开发者_高级运维eader and iterating through all the resulted rows?if you cant ch

Is there an easier way of doing this besides loading the data into a DataTable and using Rows.Count or using a MySqlDataR开发者_高级运维eader and iterating through all the resulted rows?


if you cant change the query easily

SELECT COUNT(*) FROM (<your complete query here>)


You can execute a query like:

SELECT COUNT(*) FROM MyTable;


You can use the MySQL informational function FOUND_ROWS. Just run it immediately after your SELECT query. Like this:

SELECT FOUND_ROWS()


Exec an

select count(*) from MyTable WHERE <clause>

and get the result with ExecuteScalar()

0

精彩评论

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