c# - Three tiers select date from two tables -
i have tried googling lot of things, couldn't find answer - hoping me out!
what i'm trying do: on winform application need select computername through combobox, upon selection, listbox populated data computer (softwarename, version , stuff)
the combobox working id, not other fields.
my listview, using database call, listed bellow:
clsoftwareperpc sf = new clsoftwareperpc(); datatable dt = sf.selectsoftware(zoekid); // voor iedere rij een nieuw nummer geven (r) (int r = 0; r < dt.rows.count; r++) { lvi = new listviewitem(); // cdnummer als titel //lvi.text = (string)(dt.rows[r]["idcomputer"]); lvi.text = ((string)(dt.rows[r]["idinstallatie"]).tostring()); // titels toevoegen in deze kolom lvi.subitems.add((string)(dt.rows[r]["softwarenaam"])); lvi.subitems.add((string)(dt.rows[r]["ontwikkelaar"])); lvi.subitems.add((string)(dt.rows[r]["omschrijving"])); lvi.subitems.add((string)(dt.rows[r]["versie"])); lvi.subitems.add(((string)(dt.rows[r]["updatedatum"]).tostring())); lvi.tag = (((string)(dt.rows[r]["idinstallatie"]).tostring())); // alle opgevraagde velden weergeven lv.items.add(lvi); } // wanneer er records zijn if (dt.rows.count > 0) { // eerste rij selecteren lv.items[0].selected = true; lv.select(); }
my database call (working , tested) / clsoftwareperpc:
public datatable selectsoftware(string zoekid) { // selecteren van alle inhoud van tabel computers en orderen op merk naam // string sql = "select * softwareopcomputer order idcomputer model = '" + zoekid + "'"; string sql = "select * software, softwareopcomputer software.idsoftware = softwareopcomputer.idsoftware , softwareopcomputer.idcomputer = '" + zoekid + "'"; // uitoveren van query return cldatabase.executeselect(sql); }
* select now: select * [table names]
i've tried use full location one: software.version
, didn't work either. zoekid value combobox selected computer.
the database: databse looks this: pbs.twimg.com/media/bjw-wd9cmaaczio.jpg:large need fields like: softwareopcomputer.versie, softwareopcomputer.updatedatum, software.softwarenaam, software.ontwikkelaar.
when use method , use 1 table (the other pages of application) works, when use screen , need 2 tables doesn't work.
i try use join instead.
string sql = "select c.versie, c.updatedatum, s.softwarenaam, s.ontwikkelaarfrom " + "from software s inner join softwareopcomputer c " + "on s.idsoftware = c.idsoftware " + "where c.idcomputer = '" + zoekid + "'";
this produce join between software , sotwareopcomputer. returns rows software
, softwareopcomputer
tables have matched id
excluding rows don't have matching id , condition limits output.
unfortunately, use method cldatabase.executeselect
doesn't seem allow pass parameter avoid string concatenation. suggest search parametrized query , sql injection realize how code weak
another aspect wish improve loop add rows listview
foreach (datarow row in dt.rows) { lvi = new listviewitem(); lvi.text = row.field<string>("idinstallatie")); lvi.subitems.add(row.field<string>("softwarenaam")); .... etc ... }
Comments
Post a Comment