sql语句 select  DPAvgPoint from cardp where DPAvgPoint >3 
 数据库中类型 DPAvgPoint 为  decimal(18, 2)
   protected int customerTotal = 0;
   DataSet dsCustomer = Car_DPService.GetDPTotalData(1);
        DataTable dt = dsCustomer.Tables[0];
        foreach (DataRow dr in dt.Rows)
        {
            for (int i = 0; i < dt.Columns.Count; i++)
            {
                customerTotal = int.Parse(dt.ToString());
            }
        } 想要查询 数据表中 dpavgpoint 大于三的值 并累加 给 变量 customerTotal  
请问怎么写 谢谢!

解决方案 »

  1.   

    直接读出来大于三的值再累加 DataRowView view=ds.Tables[0].DefaultView
      

  2.   

    DataTable table = new DataTable();
    ....
                table.Compute("sum(dpavgpoint)", "dpavgpoint > 3");
      

  3.   

    foreach (DataRow dr in dt.Rows)
            {
               
                    customerTotal +=dr["DPAvgPoint "]
               
            }
      

  4.   

    foreach (DataRow dr in dt.Rows)
            {
             
                    customerTotal +=dr["DPAvgPoint "]
             
            } 
      

  5.   

    customerTotal += int.Parse(dr[""].ToString());
    或customerTotal += (int)dr[""]
    还可使用datatable.Compute