本帖最后由 rfderxttl 于 2012-04-28 22:28:16 编辑

解决方案 »

  1.   


    Sqlcommond cmd =new Sqlcommond();
    textBox.Text=cmd.ExecuteScalar().ToString();
      

  2.   


    SqlCommond cmd =new SqlCommond();//创建命令对象
    //这里要打开连接 
    //connection con.Open()
    textBox1.Text=cmd.ExecuteScalar().ToString();//执行查询并显示
      

  3.   


    using System.Data.SqlClient;using(SqlConnection con = new SqlConnection("Data Source=.;uid=sa;pwd=sa;Database=Northwind"))
    {
        con.Open();
        string strsql6 = "select count(sno) from student where cno='" + class1 + "' and cet4>425";
        SqlCommand cmd = new SqlCommand(strsql6,con);
         this.TextBox1.Text = cmd.ExecuteScalar().ToString();
    }
      

  4.   

    楼上的只针对了楼主的例子情况,多字段的话,要参考ExecuteReader或者用SqlAdapter的fill方法,装到DataTable里面,然后写for循环,table.Rows[i]["字段名"].ToString()可以读取字段的值
      

  5.   


    using System.Data.SqlClient;using(SqlConnection con = new SqlConnection("Data Source=.;initial catalog=Northwind;user id=sa;password=sa"))
    {
        string strsql6 = "select count(sno) from student where cno=@class1 and cet4>425";
        using(SqlCommand cmd = new SqlCommand(strsql6,con))
      { 
         con.Open();
         cmd.Parameters.AddWithValue("@class1",class1);     
         this.TextBox1.Text = cmd.ExecuteScalar().ToString();
      }
    }