
// 获得数据写入text(主方法)
private void count(object sender, EventArgs e)
{
string str1 = "select from 表名 where 条件 ";//读取整张表
MySqlConnection coon = MySQLgetMySqlCon();//连接数据库,调方法
MySqlCommand mySqlCommand1 = MySQLgetSqlCommand(str1, coon);
coonOpen();
int record1 = MySQLgetResultCount(mySqlCommand1);
coonClose();
label1Text = record1ToString();
}
//建立执行命令的语句对象
public static MySqlCommand getSqlCommand(String sql, MySqlConnection mysql)
{
MySqlCommand mySqlCommand = new MySqlCommand(sql, mysql);
return mySqlCommand;
}
//查询记录数
public static int getResultCount(MySqlCommand mySqlCommand)
{
MySqlDataReader reader = mySqlCommandExecuteReader();
int result = 0;
try
{
while (readerRead())
{
if (readerHasRows)
{
result = result + 1;
}
}
}
catch (Exception)
{
}
finally
{
readerClose();
}
return result;
}
//此方法连接数据库
public static MySqlConnection getMySqlCon()
{
String mysqlStr = "Database=test3;Data Source=127001;User Id=root;Password=123456;pooling=false;CharSet=utf8;port=3306;Allow Zero Datetime=True";
MySqlConnection mysql = new MySqlConnection(mysqlStr);
return mysql;
}
使用JDBC连接数据库 ,然后,得到某数据库中所有的表的记录总数:
SELECT SUM(table_rows) FROM information_schematables WHERE table_schema='test';
以上就是关于C#中查询数据库中记录个数并显示。全部的内容,包括:C#中查询数据库中记录个数并显示。、如何用Java实现获得MySQL数据库中所有表的记录总数、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)