asp.net - Checkbox has values of 0 and -1? -
i have checkboxes on webapp, , save button. when click save button, save checked state of checkboxes database.
when checkboxes not checked, 0's in database. however, when checked, -1's in database. expecting 1's. -1's normal checked states?
sample code:
function processaction(byval checkbox1 integer, byval checkbox2 integer) integer connection = new sqlconnection(configurationsettings.appsettings("connstring")) command = new sqlcommand("stored_procedure_name_here", connection) command.commandtype = commandtype.storedprocedure command.parameters.add(new sqlparameter("@id", sqldbtype.int, 4)).value = 100 command.parameters.add(new sqlparameter("@checkbox1", sqldbtype.int, 4)).value = checkbox1 command.parameters.add(new sqlparameter("@checkbox2", sqldbtype.int, 4)).value = checkbox2 command.connection.open() command.executenonquery() command.connection.close() return 1 end function the call:
sub buttonclick(byval source object, byval e eventargs) processaction(checkbox1.checked, checkbox2.checked) end sub
a lot depend on code in between, boolean true value conventionally represented integer value -1. depends on how handling value before gets persisted. code useful if need further help.
edit: code added shows relying on implicit cast boolean integer, resulting in -1 value. in vb, depending on version, use iif(checkbox1.checked, 1, 0) or if(checkbox1.checked, 1, 0). alternatively, keep value boolean, , save appropriate underlying dbms data type if there 1 - example, in sql server, bit data type.
Comments
Post a Comment