[英]Fill Tree View dynamically from SQL Database using C#
Please help me to populate a tree view from SQL database dynamically.请帮助我从 SQL 数据库动态填充树视图。 I am very new to C# and step by step processes are welcome.
我对 C# 非常陌生,欢迎逐步进行。 I have two table formats given in the picture below and I want to fill the tree view from database accordingly.
我在下图中给出了两种表格格式,我想相应地从数据库中填充树视图。 I searched on other resource sites also but didn't find the solution what I am looking for.
我也在其他资源网站上进行了搜索,但没有找到我正在寻找的解决方案。
Please Help !!请帮忙 !!
Please view given image,请查看给定的图像,
I suppose you have two choices我想你有两个选择
You either run a JOIN which will create a result from the db where the department name is repeated over and over, and the sub department name is unique;您可以运行一个 JOIN ,它将从数据库中创建一个结果,其中部门名称一遍又一遍地重复,并且子部门名称是唯一的; you then loop over this result set row by row with a logic of:
然后,您使用以下逻辑逐行遍历此结果集:
Or, you run two loops或者,您运行两个循环
In either case you'll need to query a db, so get that part working.在任何一种情况下,您都需要查询数据库,因此请让该部分正常工作。 Entity Framework will help if you want to use it
如果您想使用实体框架,它会有所帮助
Also, look into adding nodes to a tree view and get familiar with it - don't need a db for this, just code it up by hand manually adding nodes for practice此外,考虑将节点添加到树视图并熟悉它 - 不需要数据库,只需手动编写代码手动添加节点以进行练习
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.