C# label中显示数据库查询结果
请问一下,我要吧select count(*) from Sample where srze<1000000查询结果放在label,怎么办,具体代码 --------------------编程问答----------------------------------------编程问答--------------------
SqlCommand com= new SqlCommand(str,new SqlConnection(connectionstring));
com.Connection.Open();
label.text=com.ExecSclar();
--------------------编程问答-------------------- 差不多就这样了 --------------------编程问答-------------------- SqlConnection con = new SqlConnection(“连接数据库的字符串”);
using(SqlConnection con = new SqlConnection("Data Source=.;uid=sa;pwd=sa;Database=Northwind;"))
{
con.Open();
string strSQL = "select count(*) from Sample where srze<1000000";
using(SqlCommand cmd = new SqlCommand(strSQL,con))
{
int count = cmd.ExecuteScalar();
this.Label1.Text = count.ToString();
}
}
string sql = "select count(*) from Sample where size<1000000";
SqlCommand sqlCmd = new SqlCommand(sql, con);
SqlDataReader dr = sqlCmd.ExecuteReader();
while (dr.Read()) //读取信息
{
Lable.text= dr["size"].ToString();
}
con.Close(); --------------------编程问答--------------------
+1 --------------------编程问答--------------------
补充:.NET技术 , C#