int i;
            int count;
           
           count= ds.Tables[0].Rows.Count;
           for (i = 0; i <= count - 1; i++)
           label1.Text += ds.Tables[0].Rows[i]["员工工资"].ToString();
使用的时候什么效果都没..累加不了..是要convert么?

解决方案 »

  1.   

     int i; 
                int count; 
              
              count= ds.Tables[0].Rows.Count; 
              int sum = 0;
              for (i = 0; i <= count - 1; i++) 
             { 
                try
                {
                sum = sum + (int)ds.Tables[0].Rows[i]["员工工资"];
                }
                catch(Exception)
                {
                  MessageBox.Show("Error");
                 }
             }
             label1.Text = sum.ToString();
      

  2.   

    要的 并且格式为
    label1.Text = Convert.ToDecimal(label1.Text)+Convert.ToDecimal(ds.Tables[0].Rows[i]["员工工资"]); 
      

  3.   

    这代码用后捕获3个异常..最后label为0
    使用excerption ex捕获的异常说是system.invalidCastExcoption:指定的转换无效
      

  4.   

    int sum=0;
    foreach(DataRow dr in ds.Tables[0].Rows)
    {
         sum+=int.Parese(dr["员工工资"].ToString()); 
    }
    this.label1.text=sum.ToString();
      

  5.   

    这代码用后捕获3个异常..最后label为0
    使用excerption ex捕获的异常说是system.invalidCastExcoption:指定的转换无效
      

  6.   


    报错..说是 sum+=int.Parse(dr["员工工资"].ToString()); 输入字符串的格式不正确
    对了我数据用的是money类型保存在数据库的
      

  7.   

    Convert.ToDecimal()
    用这个转换
      

  8.   

    对了还有dr["员工工资"]这个值有可能是null或是DBNull.Value 要判断先