Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Treeview From Database

Status
Not open for further replies.

8u9i

IS-IT--Management
Jul 31, 2007
6
GB
Hi all,

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


public void dbcall()
{
SqlConnection sqlconn = new SqlConnection("user id=USERNAME;" + "password=PASSWORD;server=SERVER;" + "database=DBNAME;" + "connection timeout=30");
SqlCommand select = new SqlCommand("SELECT * from MAIN", sqlconn);
sqlconn.Open();
SqlDataReader reader = select.ExecuteReader();
DataSet ds = new DataSet();
DataTable dt = new DataTable("MainTable");
ds.Tables.Add(dt);
ds.Load(reader, LoadOption.PreserveChanges, ds.Tables[0]);

sqlconn.Close();

foreach (DataRow dr in dt.Rows)
{

////////////



}

}



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.
 
Maybe this will give you an idea ...

private void CreateOrgStructure()
{
string OrgID = ConfigurationManager.AppSettings["OrgStructureStartingPoint"].ToString();

VList<VwOrgHierarchy> Organisation = DataRepository.VwOrgHierarchyProvider.Get("orgid=" + OrgID, "OrgDesc");

TreeNode tnOrg;

foreach (VwOrgHierarchy org in Organisation)
{
tnOrg = new TreeNode();
tnOrg.Value = org.OrgID.ToString();
tnOrg.Text = org.OrgDesc.ToString();
treeView.Nodes.Add(tnOrg);

CreateTree(tnOrg, OrgID);
}
}
private void CreateTree(TreeNode node, string OrgID)
{
VList<VwOrgHierarchy> Organisation = DataRepository.VwOrgHierarchyProvider.Get("parentorgid=" + OrgID, "OrgDesc");

TreeNode childNode;

foreach (VwOrgHierarchy org in Organisation)
{
childNode = new TreeNode();
childNode.Value = org.OrgID.ToString();
childNode.Text = org.OrgDesc.ToString();
node.ChildNodes.Add(childNode);
}
}

I was standing in the park, wondering why frisbees got bigger as they came closer... then it hit me!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top