【其他-小技巧-Uipath】VB语法操作DataTable分组并求和

时间:2024-01-27 08:46:02

需要对DataTable分组求和的语法:VB.net 和C#中还有点不太一样。最后试了好多方法,要这么写

我的dataTabel数据:

 

1  (From p In dataTabel.AsEnumerable() 
2  Group By x= New With { Key.a =p.Item("name")} Into Grp = Group Select dataTabel.Clone.LoadDataRow (New Object() 
3   {grp(0)(0),grp.Sum(Function ( r )
4  if(String.IsNullOrEmpty(r("fen").ToString) 
5  or String.IsNullOrWhiteSpace(r("fen").ToString),0,Convert.ToDouble(r("fen").ToString)))},False)).CopyToDataTable

 

 

 

 

 最后成功打印: