我是菜鸟哈哈,问高手们一个问题,
            SqlConnection sqlcon = new SqlConnection(ConfigurationManager.ConnectionString["BookConnectionString"].ConnectionString);
            SqlCommand sc = new SqlCommand();
            sc.Connection = sqlcon;
            sc.CommandText = "select Sum(SumPrice) from ShopCart where UserID='" + id + "'";现在想把统计出的这个值放到一个Label(ID叫Total)里面,这句话怎么写?Total.Text =  ?

解决方案 »

  1.   

    SqlCommand()
    这是?
    label只有caption,没有text
    要写成Total.caption
      

  2.   

    http://baike.baidu.com/view/3574729.htm,看看是不是你要的
      

  3.   

    new()?   c#?试试把结果放到一个DataSet里,再取出来赋值给Label
      

  4.   

    sc.executescalar执行的时候回去一条返回值  你直接Total.Text =sc.executescalar。现在手头没c#所以忘记了sc.executescalar的返回值类型 不过貌似是datatable的  要是datatable的你就获取他的第0行0列的值就好了
      

  5.   

    额  刚刚想起来sc.executescalar()他是一个方法 要这样写
      

  6.   

    sc.CommandText = "select Sum(SumPrice) from ShopCart where UserID='" + id + "'";改为
    sc.execute('select Sum(SumPrice) from ShopCart where UserID="'+ id + '"').fields[0].asinteger
    即可了。
      

  7.   

    lz 这个代码是C#的。发错地方了。还有你的SQL好像写错了吧。后面条件。你注意看下。模糊了点。好久没有用C#了。
      

  8.   

    sc.CommandText = "select Sum(SumPrice) from ShopCart where UserID='" + id + "'";改为
    sc.execute('select Sum(SumPrice) from ShopCart where UserID="'+ id + '"').fields[0].asinteger
    即可了。支持