Link to home
Start Free TrialLog in
Avatar of Camillia
CamilliaFlag for United States of America

asked on

Looping thru datatable and adding up rows per one column

This can't be that hard but I can't come up with a solution...

1. I have a datatable

Amount  LocId
------------  -------
1.00           STL
2.00           Laundry
4.00           STL
5.50           XYZ
9.00           STL
1.50           Laundry

2. This is what I want to do -->Add up the rows per "LocId" and insert into a table. So:

14.00      STL
3.5           Laundry
5.50         XYZ

3. I thought about looping and comparing LocId from one row to the next one. If same, add up. If not, move to the next row but then I think I have to do this for second row, third one, etc. Maybe somehow with LINQ?

Again, this can't be that hard.
SOLUTION
Avatar of ste5an
ste5an
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Camillia

ASKER

Let me see. Thanks. I'll post back.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks. I'll take a look and see how I can adjust it to my actual code.
Thanks. I'll take a look and see how I can adjust it to my actual code.
Hi Camillia;

Let me know if you run into issues.

Fernando
Worked. Thanks.
Not a problem Camillia, glad to help.