C # .NET: How to create a relationship with your own data on one DataTable?

I have a data table structure -

User ID | User Name | Manager ID ------------------------------------- 1 | ABD | 2 2 | BCD | NULL 3 | KUM | 4 4 | POC | NULL 5 | OJM | 2 

In the above table, User ID - 2 is the manager of the user ID - 1.5 is similar. User ID - 4 is the manager of the user ID - 3.

How to create an independent relationship to display the hierarchical details of the Manager → Users?

+4
source share
1 answer

You must add a nested relation for the DataTable, as shown below:

 DataRelation relation = new DataRelation("ParentChild", result.Tables["Employee"].Columns["UserID"], result.Tables["Employee"].Columns["ManagerID"], true); relation.Nested = true; result.Relations.Add(relation); 

Hope this helps.

+2
source

Source: https://habr.com/ru/post/1436292/


All Articles