SQL查询出语句的结果 赋值给变量
中间数据库具体怎么写不太清楚麻烦大家帮忙了publicpartialclassDataBindingDemo:System.Web.UI.Page{protectedst...
中间数据库 具体怎么写 不太清楚 麻烦大家帮忙了
public partial class DataBindingDemo : System.Web.UI.Page
{
protected static int vote1 = 0;
protected static int vote2 = 0;
protected static int vote3 = 0;
protected void Page_Load(object sender, EventArgs e)
{
conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["SqlConnectionString"].ConnectionString);
conn.Open();
//vote1是 变量 他的值等于 SQL语句查询出来的结果 中间这块怎么写我不太清楚 麻烦大家指教
vote1=SELECT COUNT(Topic1) FROM RoundTable1 WHERE (Topic1 = 'a')
vote2=SELECT COUNT(Topic1) FROM RoundTable1 WHERE (Topic1 = 'b')
vote3=SELECT COUNT(Topic1) FROM RoundTable1 WHERE (Topic1 = 'c')
conn.Close();
this.DataBind();
} 展开
public partial class DataBindingDemo : System.Web.UI.Page
{
protected static int vote1 = 0;
protected static int vote2 = 0;
protected static int vote3 = 0;
protected void Page_Load(object sender, EventArgs e)
{
conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["SqlConnectionString"].ConnectionString);
conn.Open();
//vote1是 变量 他的值等于 SQL语句查询出来的结果 中间这块怎么写我不太清楚 麻烦大家指教
vote1=SELECT COUNT(Topic1) FROM RoundTable1 WHERE (Topic1 = 'a')
vote2=SELECT COUNT(Topic1) FROM RoundTable1 WHERE (Topic1 = 'b')
vote3=SELECT COUNT(Topic1) FROM RoundTable1 WHERE (Topic1 = 'c')
conn.Close();
this.DataBind();
} 展开
1个回答
展开全部
呵,不是太麻烦的用Reader可以实现,给你个小例子:
SqlConnection conn = new SqlConnection("Server=(local);DataBase=tmp;Uid=sa;Pwd=1122");
SqlDataReader r ;
SqlCommand cmd = new SqlCommand("select count(*) from table1",conn);
conn.Open();
r = cmd.ExecuteReader();
if (r.Read()) //如果sql查询到了数据
MessageBox.Show(r.GetInt32(0).ToString());
conn.Close();
如果还不明白发消息给我。
SqlConnection conn = new SqlConnection("Server=(local);DataBase=tmp;Uid=sa;Pwd=1122");
SqlDataReader r ;
SqlCommand cmd = new SqlCommand("select count(*) from table1",conn);
conn.Open();
r = cmd.ExecuteReader();
if (r.Read()) //如果sql查询到了数据
MessageBox.Show(r.GetInt32(0).ToString());
conn.Close();
如果还不明白发消息给我。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询