c# - Stored Procedure has too many parameters -



posibale duplicate getting 'too many parameters passed' stored procedure on aspx page


i'm using sqldatasource control update , delete functionality within gridview. keep getting runtime error procedure or function spupdatetest has many arguments specified. when run stored procedure in sql server works fine. when click on delete portion of gridview, works. however, when try update above error.

 <asp:sqldatasource id="sqldatasource1" runat="server"              connectionstring="<%$ connectionstrings:dbcsdrugcards %>"              deletecommand="spdeletetest" deletecommandtype="storedprocedure"              insertcommand="spinserttest" insertcommandtype="storedprocedure"              selectcommand="spgetalltest" selectcommandtype="storedprocedure"              updatecommand="spupdatetest" updatecommandtype="storedprocedure">             <deleteparameters>                 <asp:parameter name="patientid" type="int32" />             </deleteparameters>             <insertparameters>                 <asp:parameter name="patientid" type="int32" />                 <asp:parameter name="raceid" type="int32" />                 <asp:parameter name="countyid" type="int32" />                 <asp:parameter name="gender" type="string" />                 <asp:parameter name="dateofbirth" type="datetime" />                 <asp:parameter name="sesid" type="int32" />             </insertparameters>             <updateparameters>                 <asp:parameter name="patientid" type="int32" />                 <asp:parameter name="raceid" type="int32" />                 <asp:parameter name="countyid" type="int32" />                 <asp:parameter name="gender" type="string" />                 <asp:parameter name="dateofbirth" type="datetime" />                 <asp:parameter name="sesid" type="int32" />             </updateparameters>         </asp:sqldatasource> 

you can see 6 parameters in sqldatasource. here stored procedure

create proc spupdatetest    @patientid int   ,@raceid int   ,@countyid int   ,@gender varchar(50)   ,@dateofbirth date   ,@sesid int     begin   update t   set  t.raceid = @raceid    ,t.countyid = @countyid    ,t.gender = @gender    ,t.dateofbirth = @dateofbirth    ,t.socioeconomicstatusid = @sesid   test t   t.patientid = @patientid   end   

both have 6 parameters. gridview measure in case makes difference

   <asp:gridview id="gridview1" runat="server" autogeneratecolumns="false"              cellpadding="4" datakeynames="patientid" datasourceid="sqldatasource1"              forecolor="#333333" gridlines="none">             <alternatingrowstyle backcolor="white" forecolor="#284775" />             <columns>                 <asp:commandfield showdeletebutton="true" showeditbutton="true" />                 <asp:boundfield datafield="patientid" headertext="patientid" readonly="true"                      sortexpression="patientid" />                 <asp:boundfield datafield="raceid" headertext="raceid"                      sortexpression="raceid" />                 <asp:boundfield datafield="countyid" headertext="countyid"                      sortexpression="countyid" />                 <asp:boundfield datafield="gender" headertext="gender"                      sortexpression="gender" />                 <asp:boundfield datafield="dateofbirth" headertext="dateofbirth"                      sortexpression="dateofbirth" />                 <asp:boundfield datafield="socioeconomicstatusid"                      headertext="socioeconomicstatusid" sortexpression="socioeconomicstatusid" />                 <asp:boundfield datafield="dateenrolled" headertext="dateenrolled"  readonly="true"                     sortexpression="dateenrolled" />             </columns>             <editrowstyle backcolor="#999999" />             <footerstyle backcolor="#5d7b9d" font-bold="true" forecolor="white" />             <headerstyle backcolor="#5d7b9d" font-bold="true" forecolor="white" />             <pagerstyle backcolor="#284775" forecolor="white" horizontalalign="center" />             <rowstyle backcolor="#f7f6f3" forecolor="#333333" />             <selectedrowstyle backcolor="#e2ded6" font-bold="true" forecolor="#333333" />             <sortedascendingcellstyle backcolor="#e9e7e2" />             <sortedascendingheaderstyle backcolor="#506c8c" />             <sorteddescendingcellstyle backcolor="#fffdf8" />             <sorteddescendingheaderstyle backcolor="#6f8dae" />         </asp:gridview> 

i don't know if means anything, have 1 field, dateenrolled not meant edited user , saved database getdate() whenever test object added database.

c#

public static void updatetest(int patientid, int raceid, int countyid, string gender             , datetime dateofbirth, int sesid)         {             using (sqlconnection con = new sqlconnection(testdataaccesslayer.connectionstring))             {                 using (sqlcommand cmd = new sqlcommand("spupdatetest", con))                 {                     con.open();                     cmd.commandtype = commandtype.storedprocedure;                     cmd.parameters.addwithvalue("@racedescription", raceid);                     cmd.parameters.addwithvalue("@countyname", countyid);                     cmd.parameters.addwithvalue("@gender", gender);                     cmd.parameters.addwithvalue("@dateofbirth", dateofbirth);                     cmd.parameters.addwithvalue("@sesdescription", sesid);                     cmd.parameters.addwithvalue("@patientid", patientid);                     cmd.executenonquery();                 }             }         } 

this works

public static void deletetest(int patientid)         {             using (sqlconnection con = new sqlconnection(testdataaccesslayer.connectionstring))             {                 using (sqlcommand cmd = new sqlcommand("spdeletetest", con))                 {                     con.open();                     cmd.commandtype = commandtype.storedprocedure;                     cmd.parameters.addwithvalue("@patientid", patientid);                     cmd.executenonquery();                 }             }         } 

where mysterious parameter coming don't know about?

your parameter names in c# code not match defined in stored procedure.

here names not match in stored procedure:

  • @raceid - @racedescription in c# code
  • @countyid - @countryname in c# code
  • @sesid - @sesdescription in c# code

my guess, without seeing code, delete stored procedure, @patientid parameters matches on both sides (c# , stored procedure) why 1 works , update not.


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -