使用C#Windows应用程序将数据从SQL Server数据库中的多个表检索到Treeview [英] Retrieve data from several tables in SQL server database to Treeview using C# windows application

查看:106
本文介绍了使用C#Windows应用程序将数据从SQL Server数据库中的多个表检索到Treeview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该如何从sql server数据库&中的几个表中检索数据?在treeveiw上以分层方式显示它们,例如,我想要做的例子是:我的数据库中有4个表,它们是:
国家/地区表
CountryID国家/地区名称
1美国
2英格兰
3法国

城市表
CityID CityName CountryID
1纽约1
2 Los Anglos 1
3伦敦2

客户表
CustomerID客户名称地址城市ID
1埃里克·华尔街1
2 Beth london street 3

子客户
SubCustomerID SubCustomerName客户ID
1杰森1
2斯科特1
我想像这样在treeview中显示数据:

-美国---->父节点
----纽约----->第一个子节点
------埃里克(Eric)----->第二个子节点
-------- Jason ----->第三个子节点
--------斯科特----->第三个子节点
---- Los Anglos ----->第一个子节点
-英格兰----->父节点
----伦敦----->第一个子节点
------贝斯----->第二个子节点


谁能帮我.

How can I retrieve data from several tables in sql server database & show them in hierarchical at treeveiw, example for what I want to do is that: I have 4 tables in my database, they are:
Country table
CountryID CountryName
1 USA
2 England
3 France

City table
CityID CityName CountryID
1 New York 1
2 Los Anglos 1
3 London 2

Customers table
CustomerID CustomerName Address CityID
1 Eric wall street 1
2 Beth london street 3

SubCustomers
SubCustomerID SubCustomerName CustomerID
1 Jason 1
2 Scott 1
And I want to show my data in treeview like that:

--USA ----> Parent Node
----New York -----> first child node
------Eric -----> second child node
--------Jason -----> third child node
--------Scott -----> third child node
----Los Anglos -----> first child node
--England -----> Parent Node
----London -----> first child node
------Beth -----> second child node


Can anyone help me please.

推荐答案

获取数据很容易,您只需要提供它即可.如何从那里填充树状视图取决于您自己.一种明显而简单的方法是在最高级别填充您的国家/地区,然后遍历每个级别,在该级别搜索数据.我也发现了这个

C#中的数据绑定TreeView [
Getting the data is easy, you just ask for it. How you populate your treeview from there, is up to you. The obvious and simply way is to populate your countries at the top level, and then work through each level, searching for data at that level. I also found this:

Data Binding TreeView in C#[^]

and it looks to me like you could return a table with all your data and use this control to get it built in to a tree for you.


这篇关于使用C#Windows应用程序将数据从SQL Server数据库中的多个表检索到Treeview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆