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