Camillia
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks. I'll take a look and see how I can adjust it to my actual code.
ASKER
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
Let me know if you run into issues.
Fernando
ASKER
Worked. Thanks.
Not a problem Camillia, glad to help.
ASKER