c# - Delete multiple asp.net repeater Items with checkbox selection only -
here not show error page loading error?
c# code
protected void imgs_click(object sender, imageclickeventargs e) { foreach (repeateritem ri in repeater.items) { checkbox item_check = (checkbox)ri.findcontrol("item_check"); label txt_id = (label)ri.findcontrol("txt_id"); if (item_check.checked) { con = new sqlconnection(strcon); sqlcommand cmd = new sqlcommand("ram", con); cmd.commandtype = commandtype.storedprocedure; con.open(); cmd.parameters.addwithvalue("@action", "delete"); cmd.parameters.addwithvalue("@eid", txt_id); repeat(); } } }
asp.code
you forgot write cmd.executenonquery();
- stop using
addwithvalue
always use
using
sqlconnection
,sqlcommand
implementsidisposable
protected void imgs_click(object sender, imageclickeventargs e)
{foreach (repeateritem ri in repeater.items) { checkbox item_check = (checkbox)ri.findcontrol("item_check"); label txt_id = (label)ri.findcontrol("txt_id"); if (item_check.checked) { using(sqlconnection con = new sqlconnection(strcon)) { using(sqlcommand cmd = new sqlcommand("ram", con)) { cmd.commandtype = commandtype.storedprocedure; con.open(); cmd.parameters.add("@action",sqldbtype.varchar,50).value="delete"; cmd.parameters.add("@eid",sqldbtype.int).value=convert.toint16(txt_id.text); cmd.executenonquery(); repeat(); } } } }
}
Comments
Post a Comment