cmd.commandText="select count(*) from @s";
string s=textBox1.text.Trim();
sqlParameters sp =New SqlParameters("@s",datadbtype.string,50);
sp.value=s;
cmd.parameters.Add(sp);
//因为是自己临时打的,不是从VS里拿过来的,有好多大小写就直接忽略了,但我的程序就是这样的,
请问通过什么方法可以把select 语句的count 结果填入到textBox1.text里去?
string s=textBox1.text.Trim();
sqlParameters sp =New SqlParameters("@s",datadbtype.string,50);
sp.value=s;
cmd.parameters.Add(sp);
//因为是自己临时打的,不是从VS里拿过来的,有好多大小写就直接忽略了,但我的程序就是这样的,
请问通过什么方法可以把select 语句的count 结果填入到textBox1.text里去?
Int32 count = (Int32) cmd.ExecuteScalar();
textBox1.text = count.ToStrings();
cmd.commandText="select count(*) from "+TextBox1.Text.Trim(); //在TextBox1中输入要查的表名
int count = (int) cmd.ExecuteScalar();//执行查询,返回数据表中记录数目
TextBox2.Text = count.ToString(); //将查询结果显示到TextBox2中
int count = (int) cmd.ExecuteScalar();//返回数据表中第一行第一列的数据
string s=textBox1.text.Trim();
sqlParameters sp =New SqlParameters("@s",datadbtype.string,50)
sp.value=s;
cmd.parameters.Add(sp); textBox1.text=cmd.ExecuteScalar();
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 );