需要显示的列
DataTable AftDetail = new DataTable();
AftDetail.Columns.Add("one", typeof(string));
AftDetail.Columns.Add("two", typeof(string));
AftDetail.Columns.Add("trd", typeof(string));
AftDetail.Columns.Add("four", typeof(int));
AftDetail.Columns.Add("five", typeof(string));
AftDetail.Columns.Add("Six", typeof(decimal));
//这里的DataTable 就是原始的datatable
var query = from t in dsData.Tables[1].AsEnumerable()
group t by new
{
t1 = t.Field<string>("one"),
t2 = t.Field<string>("two"),
t3 = t.Field<string>("trd"),
t4 = t.Field<string>("five"),
} into m
select new
{
one= m.Key.t1,
two= m.Key.t2,
trd= m.Key.t3,
five= m.Key.t4,
four= m.Sum(p => p.Field<decimal>("four")),
six= m.Sum(p => p.Field<decimal>("six"))
};
然后将 query.ToList() 填充到相应的新的dataTable
标签:AftDetail,汇总,Field,Add,Columns,DataTable,列对,typeof From: https://www.cnblogs.com/bluefeng/p/16721510.html