111,119
社区成员
发帖
与我相关
我的任务
分享
public static int ExecuteNonQuery(string connectionString, string commandText)
{
try
{
using (OleDbConnection oleDbConnection = new OleDbConnection(connectionString))
{
oleDbConnection.Open();
using (OleDbCommand oleDbCommand = new OleDbCommand(commandText, oleDbConnection))
{
return oleDbCommand.ExecuteNonQuery();
}
}
}
catch
{
return -1;
}
}
调用
string sqlContext = "SELECT COUNT(*) FROM table";
textBox1.text = ExecuteNonQuery("连接数据库的字符串",sqlContext );
cmd.commandText="select count(*) from "+TextBox1.Text.Trim(); //在TextBox1中输入要查的表名
int count = (int) cmd.ExecuteScalar();//执行查询,返回数据表中记录数目
TextBox2.Text = count.ToString(); //将查询结果显示到TextBox2中
Int32 count = (Int32) cmd.ExecuteScalar();
textBox1.text = count.ToStrings();