Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Reading Data into TreeView from SQL Table

Posted on 2007-03-21
6
Medium Priority
?
237 Views
Last Modified: 2010-04-16
Hi all,
I have a table with Zip Codes in it.  From this, I want to create a tree view of data.  However, I need to drill down and give people options on what they are allowed to select.  My datatable contains 4 columns:
State, County, City, Zip
I want to create a parent node at their level (State, County, or City).  and then give them the ability to select anything below them
for instance, I am at a county level.  In the tree view, I want to see my county, then all the cities in my county and then all my zip codes in my city.  So my tree would look like this:
County
|-City1
|--Zip1C1
|--Zip2C1
|-City2
|--Zip1C2
|-City3
|--Zip1C3
|--Zip2C3
|--Zip3C3

But, if I am at the state level, I want to be able to have the state as the parent, and then each county under that, and each city....

How can I separate out the parent (I already know what level they are at) and then create all the children.  This is all in 1 table.
I do have the table set at the correct level for data reading (meaning I do a select * from table where state='mystate' if I am at state level, select * from table where state='mystate' and county='mycounty' for county level, and so on.
0
Comment
Question by:ericlockshine
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 12

Expert Comment

by:craskin
ID: 18766347
SELECT state FROM myTable GROUP ON state
0
 
LVL 12

Expert Comment

by:craskin
ID: 18766355
you can also do

SELECT DISTINCT state FROM myTable
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 2000 total points
ID: 18768197
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:ericlockshine
ID: 18771149
craskin:
I already have the data in one table from the database.  That is not what I was asking but thanks for the help.
emoreau:  Do you know how to create relationships out of the same table?  Do I have to retrieve the data in a different way to allow for the tree to be built?
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 18771624
see the code in the "Filling the Treeview" section. You need to have 2 datatables (1 for city and one for zips in your case) and establish a DataRelation between those 2 DataTables.
0
 

Author Comment

by:ericlockshine
ID: 18779549
Thanks emoreau:
I was able to populate the nodes and create the relationships.  What I had to do was this:  For each level that I was at, select the appropriate information from my database.  So, for each level I need to select one more level.  Your example gave me the information that I needed to program the tree and to decide how to select the information from the database.

I have All States, Counties, Cities and Zip Codes to load.  For each level, they get access at their level: Cities get city level and zip level, Counties get county level, city level and zip level.  Once I figured out how to get this out of the database, the rest was easy.

Thanks for your help!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

671 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question