c# - How to parameterize the Update query in SqlDataSource -


enter image description here

i maintaining old website, code pretty messy.

i want use sqldatasource updating, selecting, inserting functions. do not want write back-end code myself. (i have written code, old code messy test , not have comments makes me hard detect bugs are, have discarded back-end code , using sqldatasource)

instead, i'd use updatecommand in sqldatasource update. here updating query:

update medicarelocalaccounts set account=@account , pwd=@pwd divisionid=@divisionid 

the data source comes 3 different tables.

 <asp:gridview id="gv_medicarelocals" runat="server" allowpaging="true" allowsorting="true"             autogeneratecolumns="false" datakeynames="ludivisionsuid" clientidmode="static" autogenerateeditbutton="true"             enablepersistedselection="true" datasourceid="sqldatasource1">             <columns>                 <asp:hyperlinkfield datatextfield="ludivisionsuid" headertext="division id" showheader="true"                     sortexpression="ludivisionsuid" />                 <asp:boundfield datafield="division" headertext="medicare local" readonly="true" sortexpression="division"/>                 <asp:boundfield datafield="states" headertext="state" readonly="true" sortexpression="states" />                  <asp:templatefield headertext="account">                     <itemtemplate>                         <asp:label id="label1" runat="server" text='<%# eval("account") %>' />                     </itemtemplate>                     <edititemtemplate>                         <input type="text" clientidmode="static" runat="server" id="tbaccount" value='<%# eval("account") %>' />                     </edititemtemplate>                 </asp:templatefield>                 <asp:templatefield headertext="password">                     <itemtemplate>                         <asp:label id="label1" runat="server" text='<%# eval("pwd") %>' />                     </itemtemplate>                     <edititemtemplate>                         <input type="text" clientidmode="static" runat="server" id="tbpassword" value='<%# eval("pwd") %>' />                     </edititemtemplate>                 </asp:templatefield>             </columns>         </asp:gridview> 

so can see, need have divisionid parameterized well, divisionid field not have id (not account , password). how can write clause in order find divisionid in current row?

update: have changed divisionid column

  <asp:templatefield headertext="divisionid" sortexpression="ludivisionsuid" >                         <itemtemplate>                             <asp:label runat="server" id="lbldivisionid" text='<%# eval("ludivisionsuid") %>'>' ></asp:label>                         </itemtemplate>                     </asp:templatefield> 

but got error after clicked update button.

could not find control 'tbaccount' in controlparameter 'account'.

description: unhandled exception occurred during execution of current web request. please review stack trace more information error , originated in code.

exception details: system.invalidoperationexception: not find control 'tbaccount' in controlparameter 'account'.

source error:

an unhandled exception generated during execution of current web request. information regarding origin , location of exception can identified using exception stack trace below.

stack trace:

[invalidoperationexception: not find control 'tbaccount' in controlparameter 'account'.]
system.web.ui.webcontrols.controlparameter.evaluate(httpcontext context, control control) +2155166
system.web.ui.webcontrols.parameter.updatevalue(httpcontext context, control control) +50
system.web.ui.webcontrols.parametercollection.updatevalues(httpcontext context, control control) +101
system.web.ui.webcontrols.parametercollection.getvalues(httpcontext context, control control) +36
system.web.ui.webcontrols.sqldatasourceview.initializeparameters(dbcommand command, parametercollection parameters, idictionary exclusionlist) +257 system.web.ui.webcontrols.sqldatasourceview.executeupdate(idictionary keys, idictionary values, idictionary oldvalues) +222
system.web.ui.datasourceview.update(idictionary keys, idictionary values, idictionary oldvalues, datasourceviewoperationcallback callback) +87
system.web.ui.webcontrols.gridview.handleupdate(gridviewrow row, int32 rowindex, boolean causesvalidation) +1210
system.web.ui.webcontrols.gridview.handleevent(eventargs e, boolean causesvalidation, string validationgroup) +738
system.web.ui.webcontrols.gridview.onbubbleevent(object source, eventargs e) +89 system.web.ui.control.raisebubbleevent(object source, eventargs args) +37
system.web.ui.webcontrols.gridviewrow.onbubbleevent(object source, eventargs e) +88 system.web.ui.control.raisebubbleevent(object source, eventargs args) +37
system.web.ui.webcontrols.linkbutton.oncommand(commandeventargs e) +121 system.web.ui.webcontrols.linkbutton.raisepostbackevent(string eventargument) +156
system.web.ui.webcontrols.linkbutton.system.web.ui.ipostbackeventhandler.raisepostbackevent(string eventargument) +10
system.web.ui.page.raisepostbackevent(ipostbackeventhandler sourcecontrol, string eventargument) +13
system.web.ui.page.raisepostbackevent(namevaluecollection postdata) +9642898 system.web.ui.page.processrequestmain(boolean includestagesbeforeasyncpoint, boolean includestagesafterasyncpoint) +1724

as can see code, have applied property clientidmode="static" on both gridview , columns. use chrome see generated ids account column , found id=tbaccount, name="ctl00$pagetitleplaceholder$gv_medicarelocals$ctl02$tbaccount"

i don't think sql updateparameter going use name property anyway.

if u create stored procedure easy.for purpose visit link

hope works.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -