MieZiiS_JanX Posted March 12, 2013 Report Share Posted March 12, 2013 (edited) Varbūt kāds var palīdzēt vai dot ieteikumus... Ar šo kodu es nolasu darbinieku vārdus, bet man šos darbiniekus vajag sakārtot pēc amatiem, t.i. pēc darbs_id, piem. 1. *..... *..... *..... *..... 2. *..... *...... *...... *...... utt. P.S. kur zvaigzniite tur atkaape, kjipa cipars ir parents un zvaigniite ir child. void ieladet_koku() { treeView1.Nodes.Clear(); string lcon_string = "Server=localhost;Port=5432;Database=uznemums;User Id=roberts;Password=parole;"; NpgsqlConnection con = new NpgsqlConnection(lcon_string); NpgsqlDataAdapter DA = new NpgsqlDataAdapter(); string gq = ("SELECT * FROM darbinieki ORDER BY uzvards"); NpgsqlCommand getv = new NpgsqlCommand(gq, con); DA.SelectCommand = getv; DataTable sof = new DataTable(); DA.Fill(sof); foreach (DataRow dr in sof.Rows) { TreeNode tn = new TreeNode(); tn.Text = (dr["vards"].ToString() + " " + dr["uzvards"].ToString()); tn.Tag = dr["darbinieks_id"].ToString(); treeView1.Nodes.Add(tn); } } Edited March 12, 2013 by MieZiiS_JanX Link to comment Share on other sites More sharing options...
waplet Posted March 12, 2013 Report Share Posted March 12, 2013 SELECT * FROM darbinieki ORDER BY darbs_id Link to comment Share on other sites More sharing options...
MieZiiS_JanX Posted March 12, 2013 Author Report Share Posted March 12, 2013 tad es vnk sakartošu pēc darbs_id cipariem, diemžēl tas man nav būtiski. es nomainiju kodu uz: foreach (DataRow dr in sof.Rows) { TreeNode tn = new TreeNode(); tn.Text = (dr["nosaukums"].ToString()); treeView1.Nodes.Add(tn); } tagad parādās visi amati, bet zem katra amata man jādabū darbinieka vārds + uzvārds kā child, bet to es nekādīgi nespēju dabūt gatavu Link to comment Share on other sites More sharing options...
MieZiiS_JanX Posted March 12, 2013 Author Report Share Posted March 12, 2013 Pats tiku galā Ja nu kādam kadreiz noder, tad mans risinājums bija šāds: void ieladet_koku() { treeView1.Nodes.Clear(); //ja nu kas string lcon_string = "Server=localhost;Port=5432;Database=uznemums;User Id=roberts;Password=parole;"; NpgsqlConnection con = new NpgsqlConnection(lcon_string); NpgsqlDataAdapter DA = new NpgsqlDataAdapter(); NpgsqlDataAdapter DAA = new NpgsqlDataAdapter(); string gq = ("SELECT * FROM darbs ORDER BY darbs_id"); string gg = ("SELECT * FROM darbinieki ORDER BY uzvards"); NpgsqlCommand getv = new NpgsqlCommand(gq, con); NpgsqlCommand getvv = new NpgsqlCommand(gg, con); DA.SelectCommand = getv; DAA.SelectCommand = getvv; DataTable sof = new DataTable(); DataTable soff = new DataTable(); DA.Fill(sof); DAA.Fill(soff); foreach (DataRow dr in sof.Rows) //aizpilda r00t lvl { TreeNode tn = new TreeNode(); TreeNode td = new TreeNode(); tn.Text = (dr["nosaukums"].ToString()); treeView1.Nodes.Add(tn); } //if (tn.Text == "Direktors") //{ foreach (DataRow drr in soff.Rows) { TreeNode td = new TreeNode(); TreeNode tb = new TreeNode(); td.Text = (drr["vards"].ToString() +" "+ drr["uzvards"].ToString()); tb.Text = (drr["id_darbs"].ToString()); if (tb.Text == "1") { treeView1.Nodes[0].Nodes.Add(td); } else if (tb.Text == "2") { treeView1.Nodes[1].Nodes.Add(td); } else if (tb.Text == "3") { treeView1.Nodes[2].Nodes.Add(td); } else if (tb.Text == "4") { treeView1.Nodes[3].Nodes.Add(td); } } Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now