"Ronald S. Cook" <rc***@westinis.comwrote in message
news:B2**********************************@microsof t.com...
>I have a DataTable that looks like this:
Id Value
123 4.0
123 5.0
234 1.0
345 2.0
345 3.0
I want to end up with (probably a new DataTable) that contains the sum of
values grouped by Id like this:
Id SumOfValue
123 9.0
234 1.0
345 5.0
Anyone know how to write this?
There is no standard functionality in the DataTable itself to do this. If
you can use LINQ, then the groupby clause will do the aggregation for you.
Otherwise, you will have to sort the DataTable on the Id column, and then
loop through the rows adding the Value column until the Id changes, and then
dump the current Id and accumulated value onto the new table and repeat
until all the rows have been processed.