各位大神给的方法我用了还是不行啊
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();
  }

解决方案 »

  1.   

    this.TextBox1.Text = cmd.ExecuteScalar().ToString();
      

  2.   

    sqlconnection cn= new sqlconnection("server=localhost;database=jtgl;user=sa;password=sa");
    cn.open();
      

  3.   

    你这样当然显示不出来了~~ 程序执行完成后返回的是一个表~~你用文本框接受 当然不行了~~
    你在页面上放一个数据控件 datalist reapter 等就可以显示出来了~~
    DataList1.DataSource=ds;
      

  4.   

    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);
      cn.Open();
      this.TextBox1.Text = cmd.ExecuteScalar().ToString();
      cn.Close();
      

  5.   

    应该这么写
    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();
      }
      

  6.   

    autopostback加了,你在文本框里锁边输入一个什么值,然后鼠标在别的地方点一下,就可以了autopostback一定要为true