RockOn
RockOn

Reputation: 197

GridView - Procedure or function has too many arguments specified

I have this Stored Procedure:

USE [Events2]
GO
/****** Object:  StoredProcedure [dbo].[spUpdateRegistrantPaper]    Script Date: 11/20/2015 7:02:31 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[spUpdateRegistrantPaper]
    -- Add the parameters for the stored procedure here
        @RegistrantId int,
        @LocalNumber int,
        @LocalUnionEmail nvarchar(50),
        @DistrictId int,
        @CompletedByFirstName nvarchar(20),
        @CompletedByLastName nvarchar(25),
        @CompletedByPhone nvarchar(15),
        @FirstName nvarchar(20),
        @LastName nvarchar(25),
        @Position nvarchar(15),
        @Email nvarchar(50),
        @ShirtSize nvarchar(50),
        @Comments nvarchar(300)
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    -- Insert statements for procedure here
    UPDATE Registrant SET
        LocalNumberId = @LocalNumber,
        LocalUnionEmail = @LocalUnionEmail,
        DistrictId = @DistrictId,
        CompletedByFirstName = @CompletedByFirstName,
        CompletedByLastName = @CompletedByLastName,
        CompletedByPhone = @CompletedByPhone,
        FirstName = @FirstName,
        LastName = @LastName,
        Position = @Position,
        Email = @Email,
        ShirtSize = @ShirtSize,
        Comments = @Comments
        WHERE RegistrantId = @RegistrantId
END

And I have a GridView with an Edit and Update button.

  <UpdateParameters>
                <asp:Parameter Name="RegistrantId" Type="Int32" />
                <asp:Parameter Name="LocalNumber" Type="Int32" />
                <asp:Parameter Name="LocalUnionEmail" Type="String" />
                <asp:Parameter Name="DistrictId" Type="Int32" />
                <asp:Parameter Name="CompletedByFirstName" Type="String" />
                <asp:Parameter Name="CompletedByLastName" Type="String" />
                <asp:Parameter Name="CompletedByPhone" Type="String" />
                <asp:Parameter Name="FirstName" Type="String" />
                <asp:Parameter Name="LastName" Type="String" />
                <asp:Parameter Name="Position" Type="String" />
                <asp:Parameter Name="Email" Type="String" />
                <asp:Parameter Name="ShirtSize" Type="String" />
                <asp:Parameter Name="Comments" Type="String" />
            </UpdateParameters>

But I am getting this error:

Procedure or function spUpdateRegistrantPaper has too many arguments specified.

I don't see why...??? What can I do to fix this?

EDIT

Here is full asp.net code:

<%@ Page Title="" Language="C#" MasterPageFile="~/admin/admin.master" AutoEventWireup="true" CodeFile="viewregistrantpaper.aspx.cs" Inherits="viewreg" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<h1>View Registrant</h1>
        <asp:GridView ID="GridView1"  runat="server" AllowPaging="True" 
            AllowSorting="True" AutoGenerateColumns="False" 
            DataSourceID="SqlDataSourceViewRegistrant"  
            CssClass="mGrid"  
    PagerStyle-CssClass="pgr"  
    AlternatingRowStyle-CssClass="alt" >
            <Columns>
                <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
                <asp:BoundField DataField="LocalNumberId" HeaderText="Local" 
                    SortExpression="LocalNumberId" />
                <asp:BoundField DataField="LocalUnionEmail" HeaderText="Local Email" 
                    SortExpression="LocalUnionEmail" />
                <asp:BoundField DataField="DistrictId" HeaderText="District" 
                    SortExpression="DistrictId" />
                <asp:BoundField DataField="CompletedByFirstName" HeaderText="Completed By First Name" 
                    SortExpression="CompletedByFirstName" />
                <asp:BoundField DataField="CompletedByLastName" HeaderText="Completed By Last Name" 
                    SortExpression="CompletedByLastName" />
                <asp:BoundField DataField="CompletedByPhone" HeaderText="Completed By Phone" 
                    SortExpression="CompletedByPhone" />
                <asp:BoundField DataField="FirstName" HeaderText="First Name" 
                    SortExpression="FirstName" />
                <asp:BoundField DataField="LastName" HeaderText="Last Name" 
                    SortExpression="LastName" />
                <asp:BoundField DataField="Position" HeaderText="Position" 
                    SortExpression="Position" />
                <asp:BoundField DataField="Email" HeaderText="Email" 
                    SortExpression="Email" />
                <asp:BoundField DataField="ShirtSize" HeaderText="Shirt Size" 
                    SortExpression="ShirtSize" />
                <asp:BoundField DataField="Comments" HeaderText="Comments" 
                    SortExpression="Comments" />
            </Columns>

        </asp:GridView>
    <div style=" width:100%; overflow: hidden;">
        <asp:SqlDataSource ID="SqlDataSourceViewRegistrant" runat="server" 
            ConnectionString="<%$ ConnectionStrings:Events2 %>" 
            DeleteCommand="spDelRegistrant" DeleteCommandType="StoredProcedure" 
            InsertCommand="spInsRegistrantPaper" InsertCommandType="StoredProcedure" 
            SelectCommand="spGetRegistrantPaper" SelectCommandType="StoredProcedure" 
            UpdateCommand="spUpdateRegistrantPaper" 
            UpdateCommandType="StoredProcedure">
            <DeleteParameters>
                <asp:Parameter Name="RegistrantId" Type="Int32" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="LocalNumber" Type="Int32" />
                <asp:Parameter Name="LocalUnionEmail" Type="String" />
                <asp:Parameter Name="DistrictId" Type="Int32" />
                <asp:Parameter Name="CompletedByFirstName" Type="String" />
                <asp:Parameter Name="CompletedByLastName" Type="String" />
                <asp:Parameter Name="CompletedByPhone" Type="String" />
                <asp:Parameter Name="FirstName" Type="String" />
                <asp:Parameter Name="LastName" Type="String" />
                <asp:Parameter Name="Position" Type="String" />
                <asp:Parameter Name="Email" Type="String" />
                <asp:Parameter Name="ShirtSize" Type="String" />
                <asp:Parameter Name="Comments" Type="String" />
            </InsertParameters>
            <UpdateParameters>
                <asp:Parameter Name="RegistrantId" Type="Int32" />
                <asp:Parameter Name="LocalNumber" Type="Int32" />
                <asp:Parameter Name="LocalUnionEmail" Type="String" />
                <asp:Parameter Name="DistrictId" Type="Int32" />
                <asp:Parameter Name="CompletedByFirstName" Type="String" />
                <asp:Parameter Name="CompletedByLastName" Type="String" />
                <asp:Parameter Name="CompletedByPhone" Type="String" />
                <asp:Parameter Name="FirstName" Type="String" />
                <asp:Parameter Name="LastName" Type="String" />
                <asp:Parameter Name="Position" Type="String" />
                <asp:Parameter Name="Email" Type="String" />
                <asp:Parameter Name="ShirtSize" Type="String" />
                <asp:Parameter Name="Comments" Type="String" />
            </UpdateParameters>
        </asp:SqlDataSource>
        </div>
    </p>

</asp:Content>

Upvotes: 1

Views: 1707

Answers (1)

Andrei
Andrei

Reputation: 56716

Notice that you are using a lot of BoundFields in your GridView. The thing to know about these fields is that their values are added to the update/insert commands automatically. So for instance:

<asp:BoundField DataField="LocalNumberId" HeaderText="Local" 
    SortExpression="LocalNumberId" />

This will result in param LocalNumberId being added to the call of your stored proc. Since you already have just LocalNumber as a param, LocalNumberId turns out as an unexpected. Thus you have all parameters you explicitly declared in UpdateParameters tag as well as others which are in a BoundField.

Your options that I see here:

  1. Make sure BoundFields represent accurately params you want in the stored proc, rename columns or stored proc params as needed.

  2. Get rid of bound fields, use TemplateFields with Eval instead. Simple example:

    Instead of

    <asp:BoundField DataField="LocalNumberId" HeaderText="Local" 
                SortExpression="LocalNumberId" />
    

    You would have

    <asp:TemplateField HeaderText="Local" SortExpression="LocalNumberId">
        <ItemTemplate>
            <%# Eval("LocalNumberId") %>
        </ItemTemplate>
    </asp:TemplateField>
    
  3. Manually write call to the stored proc as UpdateCommand, using only params you require

Upvotes: 1

Related Questions