SqlCommand cmd = new SqlCommand("SELECT SUBSTRING(BCD,1,1)[PARENT], BCD, DESCRIPTION from BALANCE_SHEET where TYPE = 'S' GROUP BY BCD, DESCRIPTION", con); SqlDataAdapter sda = new SqlDataAdapter(cmd); sda.Fill(DT); var treeParent = DT.AsEnumerable().Select(a => a.Field<string>("parent")).Distinct(); int count = 0; foreach(string row in treeparent) { var des = DT.AsEnumerable().Where(b => b.Field <string>("BCD") == row).CopyToDataTable(); string ParentNode = row + " - " + Des.Rows[0]["DESCRIPTION"].ToString(); TreeViewBcd.Nodes.Add(ParentNode); var dtnodeList = DT.AsEnumerable().Where(c => c.Field<string>("BCD").Contains(row) && !Equals(row.Substring(0))).CopyToDataTable(); foreach(DataRow dataRow in dtnodeList.Rows) { if (!dataRow["BCD"].ToString().Equals(row)) { string childNode = dataRow.ItemArray[1].ToString() + " - " + dataRow.ItemArray[2].ToString(); TreeViewBcd.Nodes[count].Nodes.Add(childNode); } } count++; } con.Close();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)