Click here to Skip to main content
15,899,314 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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...
Posted

Hi
Try this
DataTable dt; // ... populate DataTable
var sum = dt.AsEnumerable().Sum(dr => dr.Field<Decimal>("C"));
 
Share this answer
 
Refer below linq for your reference.

http://msdn.microsoft.com/en-us/library/bb534801.aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900