问题描述
请问一下,我要吧selectcount(*)fromSamplewheresrze<1000000查询结果放在label,怎么办,具体代码
解决方案
解决方案二:
SqlCommandcom=newSqlCommand(str,newSqlConnection(connectionstring));com.Connection.Open();label.text=com.ExecSclar();
解决方案三:
using(SqlConnectioncon=newSqlConnection("DataSource=.;uid=sa;pwd=sa;Database=Northwind;")){con.Open();stringstrSQL="selectcount(*)fromSamplewheresrze<1000000";using(SqlCommandcmd=newSqlCommand(strSQL,con)){intcount=cmd.ExecuteScalar();this.Label1.Text=count.ToString();}}
解决方案四:
差不多就这样了
解决方案五:
SqlConnectioncon=newSqlConnection(“连接数据库的字符串”);stringsql="selectcount(*)fromSamplewheresize<1000000";SqlCommandsqlCmd=newSqlCommand(sql,con);SqlDataReaderdr=sqlCmd.ExecuteReader();while(dr.Read())//读取信息{Lable.text=dr["size"].ToString();}con.Close();
解决方案六:
引用2楼taomanman的回复:
C#codeusing(SqlConnectioncon=newSqlConnection("DataSource=.;uid=sa;pwd=sa;Database=Northwind;")){con.Open();stringstrSQL="selectcount(*)fromSamplewheresrze<1000000"……
+1