I have the following table in my database:
ID IsLeaf Description Parent_ID value
1--------0 ------------11--------------0-------------0
2--------0 ------------22--------------0-------------0
3--------1 ------------110001----------1-------------100
4--------0 ------------2202------------2-------------0
5--------1 ------------22020001--------4-------------159
6--------1 ------------110002----------1-------------40
I want the sum of the children to be in its parent, and when the parent is also a child of another parent, then the sum of the parents should be in its parent.
When I retrieve data I want to get it like this in a
DataTable
. I use Winforms and C#.
ID IsLeaf Description Parent_ID value
1--------0 ------------11--------------0-------------140
2--------0 ------------22--------------0-------------159
3--------1 ------------110001----------1-------------100
4--------0 ------------2202------------2-------------159
5--------1 ------------22020001--------4-------------159
6--------1 ------------110002----------1-------------40
this some Notes:
1-IsLeaf column:
if 1 "true" that's mean the Record can take value and can not make child of it.
if 0 "false" that's mean the Record can not take value and can make child of it.
but in dataTable the Parent Record Has The Sum Of Its Child
2-If the solution Need any Edit In columns (Add or Remove) thats not problem.
i need solution
I appreciate any replies or advice. Thank you.