开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜