从SQL server数据库中的几个表中检索数据到Treeview

本文关键字:检索 几个 数据 Treeview server SQL 数据库 | 更新日期: 2023-09-27 18:01:24

如何从sql server数据库中的几个表中检索数据&在windows应用程序的分层视图中显示它们,我想做的例子是:

我的数据库中有4个表,它们是:


**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

我想这样在treeview中显示我的数据:

--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

谁能帮帮我,我用的是Visual studio 2010 - c#和MS-SQL Server 2008。

从SQL server数据库中的几个表中检索数据到Treeview

最好的现代解决方案是创建一个WPF应用程序(用于GUI)并使用ADO访问数据库。. NET, LINQ to SQL或实体框架

一个使用WPF和LINQ to SQL将数据库数据绑定到列表的例子可以在这里找到:

数据库绑定示例