?
Solved

SQL Error Message:  'Procedure or function spTestUpdate has too many arguments specified.'

Posted on 2013-06-19
4
Medium Priority
?
534 Views
Last Modified: 2013-06-20
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.SqlException: Procedure or function spTestUpdate has too many arguments specified.
0
Comment
Question by:Mariyam
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 41

Expert Comment

by:guru_sami
ID: 39260476
Can you share the GridView and SqlDataSource code.
0
 

Author Comment

by:Mariyam
ID: 39260699
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="SQLDSNonEmployeeForm"
                        AutoGenerateColumns="False" DataKeyNames="SafetyIncidentID">
            <Columns>
                <asp:CommandField ShowEditButton="True" />
                <asp:BoundField DataField="SafetyIncidentID" HeaderText="SafetyIncidentID"
                    ReadOnly="True" SortExpression="SafetyIncidentID" />
                <asp:BoundField DataField="IncidentDate" HeaderText="IncidentDate"
                    SortExpression="IncidentDate" />
                <asp:BoundField DataField="IncidentTime" HeaderText="IncidentTime"
                    SortExpression="IncidentTime" />
           <asp:BoundField DataField="IncidentLocationID" HeaderText="IncidentLocationID"
                    SortExpression="IncidentLocationID" />
            </Columns>
</asp:GridView>

 <asp:SqlDataSource ID="SQLDSNonEmployeeForm" runat="server"
            ConnectionString="<%...%>"
            SelectCommand="spTest" SelectCommandType="StoredProcedure"
            UpdateCommand="spTestUpdate" UpdateCommandType="StoredProcedure">
            <UpdateParameters>
                <asp:ControlParameter ControlID="GridView1" Name="SafetyIncidentID"
                    PropertyName="SelectedValue" />
                <asp:ControlParameter ControlID="GridView1" Name="IncidentLocationID"
                    PropertyName="SelectedValue" Type="Int32" />
            </UpdateParameters>
</asp:SqlDataSource>
0
 
LVL 41

Accepted Solution

by:
guru_sami earned 1100 total points
ID: 39260742
Check this: http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_23829093.html
So I think SafetyIncidentID might be added twice. Try removing it and see if that works for you.
0
 

Author Closing Comment

by:Mariyam
ID: 39263792
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.
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question