Code Comments
Programming Forum and web based access to our favorite programming groups.I have a question that I could use some help on. I'm new to the 3.5 version of Visual studio and I'm creating my first projec t with it. What I'm trying to do is create a TreeView that is populated from a couple o f Sql Objects, one is a view, the other is a table. What is happening is I can get the parent node to populate but when I try to add the child node the parent nodes just replicate. I know I'm close but wh at am I missing? here is my code Snippet:code:
//create a dataset object DataSet ds = new DataSet(); String sqlString = "Select descr, abbrev, orglvl, active, recid From dbo.org anizationlist Order By 2"; String sqlString2 = "Select a.recid as deptid, a.descr as descr1, a.abbrev, a.orglvl, a.active ,b.[contact id] as cid ,rtrim(b.fname) + ' ' + IsNull(R Trim(b.mint),'') + ' ' + rtrim(b.sirname) as Contact ,b.fname,isnull(mint,' '),b.mint,b.sirname From dbo.organizationlist a join dbo.vw_Contacts_by_OrgL ist b On a.recid = b.[dept id] order by 3"; //create an dataadapter SqlDataAdapter da = new SqlDataAdapter(sqlString.ToString(), sqlDS.Connectio nString.ToString()); //fill the dataset through the adapter da.Fill(ds, "organizationlist"); //create an dataadapter1 SqlDataAdapter da1 = new SqlDataAdapter(sqlString2.ToString(), sqlDS.Connect ionString.ToString()); //fill the dataset through the adapter da1.Fill(ds, "contacts"); ds.Relations.Add("OrgToContacts",ds.Tables["organizationlist"].Columns["reci d"], ds.Tables["contacts"].Columns["deptid"]); //foreach loop(s) foreach (DataRow dr in ds.Tables ["organizationlist"].Rows) { TreeNode tn = new TreeNode(); //DataRow dr = new DataRow(); //nodeSupp = new TreeNode(); //nodeSupp.Text = rowSupp("CompanyName"); tn.Text = dr["descr"].ToString(); tn.Value = dr["recid"].ToString(); //.ID = rowSupp("SupplierID"); //TreeView1.Nodes.Add(nodeSupp); this.TreeView5.Nodes.Add(tn); foreach (DataRow cr in dr.GetChildRows("OrgToContacts")) / /"contacts"].Rows) { TreeNode cn = new TreeNode(); cn.Text = cr["descr1"].ToString(); cn.Value = cr["cid"].ToString(); tn.ChildNodes.Add(cn); } } //clean up ds.Dispose(); da.Dispose(); da1.Dispose(); sqlDS.Dispose();![]()
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.