Filter using a combobox
hello everyone,
i working on filter function sql database (c#), , running bit of difficulties, , thought i'd ask if can see wrong code.
in program, have 3 comboboxes: gendcombo, agecombo, , regioncombo. have filled them (except region) with search criteria (i want other 2 working first). when hit onrunfilterbtn, load filtered criteria listview... composed of 5 items: id, title, text, age, gend.
i'm not sure going wrong one, , direction helpful. tried load columns (age, example) combobox, didn't seem want work me, went ahead , added myself. tried change
string strsql = "select ca_titel, ca_alter, ca_sex fragenkatalog";
to
string strsql = "select * fragenkatalog";
which didn't work either.
i believe either not filtering of columns of database (i.e. 3 of them) , can't spit them listview, or strsqlfilter line foul. either way, i'm not sure it, , therefore grateful help,
thanks again,
martina
here's code, if helps. if have not provided enough, please let me know. :)
thanks,
m.
// agecombo
// this.agecombo.font = new system.drawing.font("tahoma", 8.25f, system.drawing.fontstyle.regular); this.agecombo.items.add(""); this.agecombo.items.add("0"); this.agecombo.items.add("1"); this.agecombo.items.add("2"); this.agecombo.items.add("3"); this.agecombo.items.add("4"); this.agecombo.items.add("5"); this.agecombo.items.add("6"); this.agecombo.items.add("7"); this.agecombo.items.add("8"); this.agecombo.items.add("9"); this.agecombo.items.add("10"); this.agecombo.items.add("11"); this.agecombo.items.add("12"); this.agecombo.items.add("13"); this.agecombo.items.add("14"); this.agecombo.items.add("15"); this.agecombo.items.add("16"); this.agecombo.items.add("17"); this.agecombo.items.add("18"); this.agecombo.items.add("999"); this.agecombo.location = new system.drawing.point(48, 16); this.agecombo.size = new system.drawing.size(80, 21); // // regioncombo // this.regioncombo.font = new system.drawing.font("tahoma", 8.25f, system.drawing.fontstyle.regular); this.regioncombo.location = new system.drawing.point(48, 40); this.regioncombo.size = new system.drawing.size(80, 21); // // gendcombo // this.gendcombo.font = new system.drawing.font("tahoma", 8.25f, system.drawing.fontstyle.regular); this.gendcombo.items.add(""); this.gendcombo.items.add("m"); this.gendcombo.items.add("f"); this.gendcombo.items.add("n"); this.gendcombo.location = new system.drawing.point(48, 64); this.gendcombo.size = new system.drawing.size(80, 21); //private void onrunfilterbtn(object sender, system.eventargs e)
{
// filter criteria//ca_titel regioncombo, ca_alter agecombo, ca_sex gendcombo
string strsql = "select ca_titel, ca_alter, ca_sex fragenkatalog"; string strsqlfilter = ""; if ( (int)gendcombo.selectedindex > 0 ){
if ( strsqlfilter.length > 0 ){
strsqlfilter += " , ";
}
strsqlfilter += "ca_sex = " + gendcombo.selectedindex.tostring();
}
if ( (int)agecombo.selectedindex > 0 ){
if ( strsqlfilter.length > 0 ){
strsqlfilter += " , ";
}
strsqlfilter += "ca_alter = " + agecombo.selectedindex.tostring();
}
if ( (int)regioncombo.selectedindex > 0 ){
if ( strsqlfilter.length > 0 ){
strsqlfilter += " , ";
}
strsqlfilter += "ca_titel = " + regioncombo.selectedindex.tostring();
}
loadlist(strsql);
}
code you've posted won't filter constructing string not used. used in code you've omitted? if so, how?
SQL Server > SQL Server Compact
Comments
Post a Comment