日期:2014-05-20 浏览次数:20843 次
DataTable linshitable = new DataTable(); var x =un_unittable.Rows.Cast<DataRow>(); var y = from p in x group p by p[0] into g select new { g.Key, TotalPrice = g.Sum(p => Convert.ToInt16(p[1])) }; DataRow drows; linshitable.Columns.Add("barcode", typeof(string)); linshitable.Columns.Add("number", typeof(int)); linshitable.Columns.Add("goodsname",typeof(string)); foreach (var v in y) { drows = linshitable.NewRow(); drows[0] = v.Key; drows[1] = v.TotalPrice; linshitable.Rows.Add(drows); } return linshitable;