Sum of column in a datatable

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can anyone tell me how i can get the sum of a datatable coloumn?
I tried to use the Sum("ColumnName") but this does not work

I want to sum this value and place the result in a label.
 
Hi,

There is DataTable.Compute method which you might use.
BTW, I don't see how you could sum a name...
 
What isn't working? Is it returning the wrong data or is it throwing an
exception?

How are you using this, via an expression column or via compute? If you use
COmpute, you'll need to add a condition.
 
Hi Miha,

what i wanted to do is to have one column in my datatable that has a sum of another columns values. i.e. Col_3 below sums the values from Col_2. Each sum is based on a single orderNo.

i.e
OrderNo Col_2 Col_3
1 2
1 23
1 5 30
2 3
2 3 6

is this possible?
 
Hi X,

I don't think it is possible.
You should manually put the values there..it is the best approach.

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

X said:
Hi Miha,

what i wanted to do is to have one column in my datatable that has a sum
of another columns values. i.e. Col_3 below sums the values from Col_2. Each
sum is based on a single orderNo.
 
Back
Top