开发者

Retrieve data from several tables in SQL server database to Treeview

开发者 https://www.devze.com 2023-03-17 11:07 出处:网络
How can I retrieve data from several tables in sql server database & show them in hierarchical at treeveiw in windows application, example for what I want to do is that:

How can I retrieve data from several tables in sql server database & show them in hierarchical at treeveiw in windows application, 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 no开发者_运维知识库de
------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, I use Visual studio 2010 - C# - and MS-SQL Server 2008.


The best modern solution is to create a WPF application (for the GUI) and access the database using either ADO.NET, LINQ to SQL or Entity Framework.

An example of binding database data to a list using WPF and LINQ to SQL can be found here:

Example of DB binding

0

精彩评论

暂无评论...
验证码 换一张
取 消