how to get group total in self refrenced data in data table ?

Posted by Nikhil Vaghela on Stack Overflow See other posts from Stack Overflow or by Nikhil Vaghela
Published on 2010-03-21T05:51:19Z Indexed on 2010/03/21 6:01 UTC
Read the original article Hit count: 351

Filed under:
|

I have three columns in my data table.

1) ProductID
2) ProductParentID
3) ProductTotal

ProductID and ProductParentID are self refrencing columns where i can set parent child relationship and get child rows based on my relationship. Let us say i have following data
Product1
    Product11
    Product12
    Product13
        Product131
        Product132
        Product133
Product2
    Product21
    Product22
    Product23

Next to above hierarchy in Product total column what i want is total of each child rows and sum of those child rows product total should be rolled up to it parent product. E.g if Product 131 total is 10,Product 13 total is 15 and Product 133 total is 5 then the product 13 total should be 30. The logic should work for n number of self hierarchy.

Is there any functionality in data table itself where i can achieve this without iterating through each row and do it manually ?

Thanks.

© Stack Overflow or respective owner

Related posts about ADO.NET

Related posts about c#