各位大神给的方法我用了还是不行啊
cn也打开了。autopostback也加了
放了个textbox,想运行程序后能在这个textbox里显示出统计次数的结果的,但是一无所获。sql代码在数据库里执行的时候是能成功统计出结果的。。求解原因
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection("server=localhost;database=jtgl;user=sa;password=sa");
SqlCommand cmd = new SqlCommand("select count(bltype) from ajd where bltype=1", cn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
cn.Open();
da.Fill(ds, "ajd");
cmd.ExecuteScalar();
this.TextBox1.Text = cmd.ExecuteScalar().ToString();
cn.Close();
}
cn也打开了。autopostback也加了
放了个textbox,想运行程序后能在这个textbox里显示出统计次数的结果的,但是一无所获。sql代码在数据库里执行的时候是能成功统计出结果的。。求解原因
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection("server=localhost;database=jtgl;user=sa;password=sa");
SqlCommand cmd = new SqlCommand("select count(bltype) from ajd where bltype=1", cn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
cn.Open();
da.Fill(ds, "ajd");
cmd.ExecuteScalar();
this.TextBox1.Text = cmd.ExecuteScalar().ToString();
cn.Close();
}
cn.open();
你在页面上放一个数据控件 datalist reapter 等就可以显示出来了~~
DataList1.DataSource=ds;
SqlCommand cmd = new SqlCommand("select count(bltype) from ajd where bltype=1", cn);
cn.Open();
this.TextBox1.Text = cmd.ExecuteScalar().ToString();
cn.Close();
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection("server=localhost;database=jtgl;user=sa;password=sa");
SqlCommand cmd = new SqlCommand("select count(bltype) as 总数 from ajd where bltype=1", cn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
cn.Open();
da.Fill(ds, "ajd");
DataTable dt=new DataTable();
dt=ds.Tables["ajd"]
this.TextBox1.Text = dt.rows[0]["总数"].ToString();
cn.Close();
}