如何获得数据表的列总和?使用LINQ [英] How will get a column sum of datatable? using LINQ
本文介绍了如何获得数据表的列总和?使用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[^]
这篇关于如何获得数据表的列总和?使用LINQ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文