private void PopulateTreeview() { SqlConnection con = new SqlConnection(connectionString); SqlCommand com = new SqlCommand("GLD_CHART_OF_ACCOUNTS_some_select", con); com.CommandType = CommandType.StoredProcedure; con.Open(); SqlDataAdapter adbt = new SqlDataAdapter(com); DataSet ds = new DataSet(); com.ExecuteNonQuery(); adbt.Fill(ds, "GLD_CHART_OF_ACCOUNTS"); con.Close(); DataTable dt = ds.Tables[0]; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { string nodeID = ds.Tables[0].Rows[i][0].ToString(); //Get the node code 'Node number' string nodeName = ds.Tables[0].Rows[i][1].ToString(); // Get the node name string Fullname = nodeID + nodeName; //Concatenate the number + name to get the full node name string parent_ID = ds.Tables[0].Rows[i][2].ToString(); //Get the parent ID of the node if (parent_ID == "0") { TreeNode node = new TreeNode(); node.Text = Fullname; TreeView1.Nodes.Add(node); } else { //GLD_CHART_OF_ACCOUNTSSelect SqlCommand command = new SqlCommand("GLD_CHART_OF_ACCOUNTSSelect", con); command.CommandType = CommandType.StoredProcedure; SqlDataAdapter adp = new SqlDataAdapter(command); DataSet IdSet = new DataSet(); { con.Open(); command.Parameters.Add("@ACCOUNT_CODE", DbType.Int32).Value = Convert.ToInt32(parent_ID); } command.ExecuteNonQuery(); adp.Fill(IdSet, "GLD_CHART_OF_ACCOUNTS"); con.Close(); string Parent_name = IdSet.Tables[0].Rows[0][0].ToString() + IdSet.Tables[0].Rows[0][1].ToString(); TreeNode node = new TreeNode(); node.Text = Fullname; TreeView1.FindNode(Parent_name).ChildNodes.Add(node); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)