MySQL获取行数 [英] MySql get number of rows
本文介绍了MySQL获取行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用以下方法从表中获取行数:
I try to get number of rows from a table with this :
string commandLine = "SELECT COUNT(*) FROM client";
using (MySqlConnection connect = new MySqlConnection(connectionStringMySql))
using (MySqlCommand cmd = new MySqlCommand(commandLine, connect))
{
connect.Open();
int count = (int)cmd.ExecuteScalar();
return count;
}
我得到了例外:
Specified cast is not valid.
有什么主意我可以解决吗?
Any idea how i can fix it?
推荐答案
尝试一下
using (MySqlCommand cmd = new MySqlCommand(commandLine, connect))
{
connect.Open();
return Convert.ToInt32(cmd.ExecuteScalar());
}
这篇关于MySQL获取行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文