Mariyam
asked on
SQL Error Message: 'Procedure or function spTestUpdate has too many arguments specified.'
Any assistance with this would be really appreciated. I've Googled for an answer and can't find anything which specifically deals with the UPDATE command of a gridview, which is bound to a SQLDataSource. I'm using a stored procedure because information has to be added to other tables and their identity values updated in the original table.
I've attempted to isolate the error by creating a test sproc which is passed 2 parameters, a LocationID from the gridview control and a session variable which is used in the UPDATE's WHERE clause.
The SQL procedure executes as expected, I've added the 2 parameter to the SQLDataSource's UPDATE command and set their values to the applicable values and then in debug mode in the ASP.NET page I've checked to make sure that the SQLDataSource has a parameter count of 2 and that they are the same parameters that the SQL sproc is expecting yet I'm still getting this error message.
This is the message:
Procedure or function spTestUpdate has too many arguments specified.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlE xception: Procedure or function spTestUpdate has too many arguments specified.
I've attempted to isolate the error by creating a test sproc which is passed 2 parameters, a LocationID from the gridview control and a session variable which is used in the UPDATE's WHERE clause.
The SQL procedure executes as expected, I've added the 2 parameter to the SQLDataSource's UPDATE command and set their values to the applicable values and then in debug mode in the ASP.NET page I've checked to make sure that the SQLDataSource has a parameter count of 2 and that they are the same parameters that the SQL sproc is expecting yet I'm still getting this error message.
This is the message:
Procedure or function spTestUpdate has too many arguments specified.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlE
Can you share the GridView and SqlDataSource code.
ASKER
I noticed that in the html the 'SafetyIncidentID' doesn't include a datatype. I added a type of Int32 and it didn't affect anything.
<asp:GridView ID="GridView1" runat="server" DataSourceID="SQLDSNonEmpl oyeeForm"
AutoGenerateColumns="False " DataKeyNames="SafetyIncide ntID">
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="SafetyIncidentI D" HeaderText="SafetyIncident ID"
ReadOnly="True" SortExpression="SafetyInci dentID" />
<asp:BoundField DataField="IncidentDate" HeaderText="IncidentDate"
SortExpression="IncidentDa te" />
<asp:BoundField DataField="IncidentTime" HeaderText="IncidentTime"
SortExpression="IncidentTi me" />
<asp:BoundField DataField="IncidentLocatio nID" HeaderText="IncidentLocati onID"
SortExpression="IncidentLo cationID" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SQLDSNonEmployeeForm" runat="server"
ConnectionString="<%...%>"
SelectCommand="spTest" SelectCommandType="StoredP rocedure"
UpdateCommand="spTestUpdat e" UpdateCommandType="StoredP rocedure">
<UpdateParameters>
<asp:ControlParameter ControlID="GridView1" Name="SafetyIncidentID"
PropertyName="SelectedValu e" />
<asp:ControlParameter ControlID="GridView1" Name="IncidentLocationID"
PropertyName="SelectedValu e" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" DataSourceID="SQLDSNonEmpl
AutoGenerateColumns="False
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="SafetyIncidentI
ReadOnly="True" SortExpression="SafetyInci
<asp:BoundField DataField="IncidentDate" HeaderText="IncidentDate"
SortExpression="IncidentDa
<asp:BoundField DataField="IncidentTime" HeaderText="IncidentTime"
SortExpression="IncidentTi
<asp:BoundField DataField="IncidentLocatio
SortExpression="IncidentLo
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SQLDSNonEmployeeForm" runat="server"
ConnectionString="<%...%>"
SelectCommand="spTest" SelectCommandType="StoredP
UpdateCommand="spTestUpdat
<UpdateParameters>
<asp:ControlParameter ControlID="GridView1" Name="SafetyIncidentID"
PropertyName="SelectedValu
<asp:ControlParameter ControlID="GridView1" Name="IncidentLocationID"
PropertyName="SelectedValu
</UpdateParameters>
</asp:SqlDataSource>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I wrote a 4 paragraph response and then hit the wrong button.
In a nutshell, I deleted all of the parameters from the SQLDataSource, then set a watch on the e.Command.Parameters.Count in the SQLDataSource_Updating event which showed 4 parameters defined even though I had deleted all of them.
After interrogating the names and values of each of the e.Command.Parameters.Item( s) I discovered that ASP.Net was creating a parameter value for each field in the gridview and prefacing each of the gridview names with the SQL variable/parameter designation of '@'.
I solved the issue by added the additional parameter values to my SQL sproc and setting their default value to null.
Everything appears to be working fine now, thank you so very much.
In a nutshell, I deleted all of the parameters from the SQLDataSource, then set a watch on the e.Command.Parameters.Count
After interrogating the names and values of each of the e.Command.Parameters.Item(
I solved the issue by added the additional parameter values to my SQL sproc and setting their default value to null.
Everything appears to be working fine now, thank you so very much.