c# - SQL query with 6 checkboxes -
i have report screen 6 checkboxes tell columns report has show. when check checkboxes , click on button nothing happens. here code:
connect = new sqlconnection(@"data source=lp12;initial catalog=smmsdata;integrated security=true"); connect.open(); sqlcommand cmd = new sqlcommand(); cmd.connection = connect; cmd.commandtext = "select druksensor, flowsensor, tempsensor, kwaliteitsensor, toerental, olieverbruik" + " systeemsensorinfo" + " druksensor=@druksensor" + " , flowsensor=@flowsensor" + " , tempsensor=@tempsensor" + " , kwaliteitsensor=@kwaliteitsensor" + " , toerental=@toerental" + " , olieverbruik=@olieverbruik" ; cmd.parameters.add("@druksensor", sqldbtype.bit); cmd.parameters.add("@flowsensor", sqldbtype.bit); cmd.parameters.add("@tempsensor", sqldbtype.bit); cmd.parameters.add("@kwaliteitsensor", sqldbtype.bit); cmd.parameters.add("@toerental", sqldbtype.bit); cmd.parameters.add("@olieverbruik", sqldbtype.bit); cmd.parameters["@druksensor"].value = checkboxdruk.checked; cmd.parameters["@flowsensor"].value = checkboxflow.checked; cmd.parameters["@tempsensor"].value = checkboxtemp.checked; cmd.parameters["@kwaliteitsensor"].value = checkkwaliteit.checked; cmd.parameters["@toerental"].value = checkboxtoerental.checked; cmd.parameters["@olieverbruik"].value = checkboxolieverbruik.checked; dataset ds = new dataset(); new sqldataadapter(cmd).fill(ds); gridview1.datasource = ds.tables[0]; gridview1.databind(); gridview1.autogeneratecolumns = true;
when exclude part of code works fine checkboxes wont work.
+ " druksensor=@druksensor" + " , flowsensor=@flowsensor" + " , tempsensor=@tempsensor" + " , kwaliteitsensor=@kwaliteitsensor" + " , toerental=@toerental" + " , olieverbruik=@olieverbruik" ; cmd.parameters.add("@druksensor", sqldbtype.bit); cmd.parameters.add("@flowsensor", sqldbtype.bit); cmd.parameters.add("@tempsensor", sqldbtype.bit); cmd.parameters.add("@kwaliteitsensor", sqldbtype.bit); cmd.parameters.add("@toerental", sqldbtype.bit); cmd.parameters.add("@olieverbruik", sqldbtype.bit); cmd.parameters["@druksensor"].value = checkboxdruk.checked; cmd.parameters["@flowsensor"].value = checkboxflow.checked; cmd.parameters["@tempsensor"].value = checkboxtemp.checked; cmd.parameters["@kwaliteitsensor"].value = checkkwaliteit.checked; cmd.parameters["@toerental"].value = checkboxtoerental.checked; cmd.parameters["@olieverbruik"].value = checkboxolieverbruik.checked;
what doing wrong or can solve checkbox problem in easier way?
hope guys have answer!
try changing
cmd.parameters["@druksensor"].value = checkboxdruk.checked;
to:
cmd.parameters["@druksensor"].value = checkboxdruk.checked?1:0;
for checkbox.checked items.
or (better) take out params.add , change them addwithvalue()
cmd.parameters.addwithvalue("@druksensor",checkboxdruk.checked?1:0);
Comments
Post a Comment