統計數量
下面是將文字變0
////// 回傳數字Decimal,非數字及空白都變成0 /// /// 傳入字串。 public static Decimal ToDecimal(string pInt) { Decimal mReturn = 0; if (pInt == "") { mReturn = 0; } else { if (IsNumeric(pInt)) { mReturn = Convert.ToDecimal(pInt); } else { mReturn = 0; } } return mReturn; } var QueryA =( from u in dt1.AsEnumerable() group u by new { CX_Size = u["CX_Size"], CX_Color_Name = u["CX_Color_Name"] } into g select new { CX_Size = g.Key.CX_Size, CX_Color_Name = g.Key.CX_Color_Name, CX_Quantity = g.Sum(p => Convert.ToDecimal(PublicClass.ToDecimal(p["CX_Quantity"].ToString()))), CX_Amount = g.Sum(p => Convert.ToDecimal(PublicClass.ToDecimal(p["CX_Amount"].ToString()))) }).ToList(); 最後再用迴圈來統計 foreach (var mRowA in QueryA) { //做處理 }