Treeview From Datatable

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2008
Posts: 10
Reputation: nlblnx is an unknown quantity at this point 
Solved Threads: 0
nlblnx nlblnx is offline Offline
Newbie Poster

Treeview From Datatable

 
0
  #1
Aug 13th, 2008
Hi all,

I am trying to grab data from the database that this application is connecting to and then show entries in a treeview.


  1. public void dbcall()
  2. {
  3. SqlConnection sqlconn = new SqlConnection("user id=USERNAME;" + "password=PASSWORD;server=SERVER;" + "database=DBNAME;" + "connection timeout=30");
  4. SqlCommand select = new SqlCommand("SELECT * from MAIN", sqlconn);
  5. sqlconn.Open();
  6. SqlDataReader reader = select.ExecuteReader();
  7. DataSet ds = new DataSet();
  8. DataTable dt = new DataTable("MainTable");
  9. ds.Tables.Add(dt);
  10. ds.Load(reader, LoadOption.PreserveChanges, ds.Tables[0]);
  11.  
  12. sqlconn.Close();
  13.  
  14. foreach (DataRow dr in dt.Rows)
  15. {
  16.  
  17. ////////////
  18.  
  19.  
  20.  
  21. }
  22.  
  23. }


The data that I am getting out of the database looks like this:


ID Hostname Username Software
1 host1 user1 sw1
2 host1 user1 sw2
3 host1 user1 sw3
4 host1 user1 sw4
5 host5 user5 sw1
6 host5 user5 sw2
7 host5 user5 sw3
8 host5 user5 sw5
9 host9 user9 sw1
10 host10 user10 sw1


I need the data to be displayed in the tree as follows, though nothing that I have done so far has been able to do it:

host1>user1>sw1
sw2
sw3
sw4
host5>user5>sw1
sw2
sw3
sw5



Any help with this would be appreciated. Thanks in advance.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,162
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 137
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Treeview From Datatable

 
0
  #2
Aug 13th, 2008
Not sure what part you have trouble with.
The concept would be loop through the results and add unique hosts to a list or hashtable and add the user to a list and each software to a list.
Then loop through the hosts, for each user in the host, for each user get software.

Create a tree node for each host, user, and software
set the child nodes of user equal to software, child nodes of host to user
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 10
Reputation: nlblnx is an unknown quantity at this point 
Solved Threads: 0
nlblnx nlblnx is offline Offline
Newbie Poster

Re: Treeview From Datatable

 
0
  #3
Aug 13th, 2008
Originally Posted by dickersonka View Post
Not sure what part you have trouble with.
The concept would be loop through the results and add unique hosts to a list or hashtable and add the user to a list and each software to a list.
Then loop through the hosts, for each user in the host, for each user get software.

Create a tree node for each host, user, and software
set the child nodes of user equal to software, child nodes of host to user
Hi,

I know what it needs to do, just can't get it to act that way. I couldn't figure out how to get the individual hosts listed and then the users, then the software as children.

The closest I've gotten is a list of all entries, so in reality about 200 of the same host with different users and software.

Any ideas?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C# Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC