Click here to Skip to main content
14,237,810 members
Rate this:
Please Sign up or sign in to vote.
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
Rate this:
Please Sign up or sign in to vote.

Solution 1

Hi
Try this
DataTable dt; // ... populate DataTable
var sum = dt.AsEnumerable().Sum(dr => dr.Field<Decimal>("C"));
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

Refer below linq for your reference.

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

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100