表如下:
 寝室号  空位数量
  123         1
  121         2
  120         2
表名叫House1,现在定义了一个Lable1控件现在我想在Lable1控件中显示表中所有空位数量的和,
请问一下各位高手,应该怎么实现?

解决方案 »

  1.   

    select sum(空位数量) as total from House1
      

  2.   

    同上select sum(空位数量) as total from House1Lable1.Text= total;
      

  3.   

    SqlConnection conn=....
    SqlCommand com=new SqlCommand("select sum(空位数量) as total from House1",conn);
    Lable1.Text=com.ExecuteScalar().ToString();
    ...
      

  4.   

    如果你存储过程输出是output
    SqlConnection conn = new SqlConnection("server=.;pwd=sa;uid=sa;database=northwind");
    SqlCommand cmd = new SqlCommand("wzl",conn);
    cmd.CommandType = CommandType.StoredProcedure;
    int a = 0 ; SqlParameter wwww = new SqlParameter();
    wwww.Direction = ParameterDirection.InputOutput;
    wwww.Value = a;
    wwww.ParameterName = "@ww"; cmd.Parameters.Add( wwww ); conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); this.Label1.Text = wwww.Value.ToString();设置参数方向(Direction )再接受