我有以下数据表结构-
User ID | User Name | Manager ID
-------------------------------------
1 | ABD | 2
2 | BCD | NULL
3 | KUM | 4
4 | POC | NULL
5 | OJM | 2
在上表中,User ID - 2 是 User ID - 1,5 的管理员,类似地,User ID - 4 是 User Id - 3 的管理员。
如何创建 self 关系以显示经理 -> 用户的层次细节?
最佳答案
您必须为 DataTable 添加嵌套关系,如下例 -
DataRelation relation = new DataRelation("ParentChild",
result.Tables["Employee"].Columns["UserID"],
result.Tables["Employee"].Columns["ManagerID"],
true);
relation.Nested = true;
result.Relations.Add(relation);
希望这对您有所帮助。
关于C#.NET : How to create self data relationship on single DataTable?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12595612/