Click here to Skip to main content
16,015,177 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900