I need to develop a multi level marketing application in C# ,i am not able to calculate commission dynamically for all member's from database.mainly i want to calculate total child's or left and right child's for parent retrieved from database.

i have used two loop kind of recursion for getting the result.

1.first loops gets the Parent name and its child reference(either by name or ID).
2.second loops is for iterating thru table on the basis of result set i.e.child.

generally i want to first retrieve the parent and child references and then query child from table until the child has no leaves.

please give me some idea or algorithm to do the same or some kind of code.
thanks in advance

You will need a recursive loop to go down into the children and then pick up them and their siblings. Based on your requirement you might be able to produce a flattened list that you can perform your mathematics on.