第一次使用linq查询
var data = from x in source.Rows.Cast<DataRow>()
group x by x[1]
into g
select new { Key = g.Key.ToString(), Items = g};
string[] array = new string[dt1.Columns.Count];
array[i] =(from y in x.Items
where y[2].ToString().Substring(0,9) == dt1.Columns[i].ToString()
select y[3].ToString()).Sum();我想求 select y[3].ToString()的和但Sum()使用有问题,应该怎么来写,linq
var data = from x in source.Rows.Cast<DataRow>()
group x by x[1]
into g
select new { Key = g.Key.ToString(), Items = g};
string[] array = new string[dt1.Columns.Count];
array[i] =(from y in x.Items
where y[2].ToString().Substring(0,9) == dt1.Columns[i].ToString()
select y[3].ToString()).Sum();我想求 select y[3].ToString()的和但Sum()使用有问题,应该怎么来写,linq
求和怎么可以用ToString()呢
如下这种测试下:
array[i] =(from y in x.Items
where y[2].ToString().Substring(0,9) == dt1.Columns[i].ToString()
select y[3]).Sum();
我求max()或者min()必须加,不然报错
where y[2].ToString().Substring(0,9) == dt1.Columns[i].ToString()
select int.parese(y[3])).Sum().ToString();不过你代码很在逻辑上有些问题, 不如帖出些数据和期望结果来看看
或许可以帮你优化一下代码查询