C# Linq对DataTable分组求和
以下是代码:
DataTable myDT = new DataTable();
myDT.Columns.Add(new DataColumn("PM", typeof(string))); //单据编号
myDT.Columns.Add(new DataColumn("BH", typeof(string))); //编号
myDT.Columns.Add(new DataColumn("DH", typeof(string))); //工单号
myDT.Columns.Add(new DataColumn("SL",typeof(decimal))); //数量
DataRow myRow = myDT.NewRow();
myRow["PM"] = "M012013070001";
myRow["BH"] = "0001";
myRow["DH"] = "130701001";
myRow["SL"] = 100;
myDT.Rows.Add(myRow);
myRow = myDT.NewRow();
myRow["PM"] = "M012013070001";
myRow["BH"] = "0002";
myRow["DH"] = "130701001";
myRow["SL"] = 120;
myDT.Rows.Add(myRow);
myRow = myDT.NewRow();
myRow["PM"] = "M012013070001";
myRow["BH"] = "0003";
myRow["DH"] = "130701002";
myRow["SL"] = 120;
myDT.Rows.Add(myRow);
myRow = myDT.NewRow();
myRow["PM"] = "M012013070001";
myRow["BH"] = "0004";