如何获得数据表的列总和?使用LINQ
问题描述:
如何使用Linq获得一列的总和。
我的数据表填充:>三列最后一列是十进制类型。
它由4行组成我需要最后一列的总和...这将如何使用Linq查询获得
我的专栏名称是A,B,C我需要总和(C)
提前感谢...
How get sum of one column using Linq.
my datatable filled with :> three columns last column is decimal type.
its consist of 4 rows i need the sum of last column... how wil this obtain using Linq query
my column name are A,B,C i need Sum(C)
thanks in advance...
答
您好
试试这个
DataTable dt; // ...填充DataTable
var sum = dt.AsEnumerable()。Sum(dr => dr.Field< Decimal>(" C"));
Hi
Try this
DataTable dt; // ... populate DataTable
var sum = dt.AsEnumerable().Sum(dr => dr.Field<Decimal>("C"));
请参阅下面的linq以供参考。
http://msdn.microsoft.com/en-us/library/bb534801.aspx [ ^ ]
Refer below linq for your reference.
http://msdn.microsoft.com/en-us/library/bb534801.aspx[^]