方法一:
DataTable dt =newDataTable();
dt.Columns.Add(newDataColumn("C1",typeof(int)));
dt.Columns.Add(newDataColumn("C2",typeof(string)));
dt.Columns.Add(newDataColumn("C3",typeof(int)));
dt.Rows.Add(1,"a",30);
dt.Rows.Add(2,"a",40);
dt.Rows.Add(3,"b",50);
dt.Rows.Add(4,"b",60);
dt.Rows.Add(5,"a",70);
Console.WriteLine("a总和:"+dt.Compute("sum(C3)","C2='a'"));
Console.WriteLine("b总和:"+dt.Compute("sum(C3)","C2='b'"));
/*
输出:
a总和:140
b总和:110
*/
===============================================================================================
方法二:
循环计算