leonsas
leonsas

Reputation: 4908

Stored Procedure with ASP.NET. Too many arguments specified error

I'm working on changing all the hard-coded SQL statements in my app to Stored Procedures. But when I run it I get the error "Procedure or function StoredProcedure1 has too many arguments specified." Here is my SP:

    ALTER PROCEDURE dbo.StoredProcedure1

        (
        @Nombreproceso varchar(MAX),
        @AnalistaID int,
        @Hallazgos varchar(MAX)
        )

    AS
        insert into proceso (nombreProceso,analista_id,hallazgos) values (@Nombreproceso,@AnalistaID,@Hallazgos)

Here is my Data Source:

 <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
             ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
             InsertCommand="StoredProcedure1" InsertCommandType="StoredProcedure" 
             SelectCommand="StoredProcedure1" SelectCommandType="StoredProcedure">
             <InsertParameters>
                  <asp:FormParameter DefaultValue="a" FormField="nombreProcesoTextBox" 
                     Name="Nombreproceso" Type="String" />
                 <asp:FormParameter DefaultValue="1" FormField="analista_idTextBox" 
                     Name="AnalistaID" Type="Int32" />
                 <asp:FormParameter DefaultValue="aa" FormField="hallazgosTextBox" 
                     Name="Hallazgos" Type="String" />
             </InsertParameters>
             <SelectParameters>
                 <asp:FormParameter DefaultValue="a" FormField="nombreProcesoTextBox" 
                     Name="Nombreproceso" Type="String" />
                 <asp:FormParameter DefaultValue="1" FormField="analista_idTextBox" 
                     Name="AnalistaID" Type="Int32" />
                 <asp:FormParameter DefaultValue="aa" FormField="hallazgosTextBox" 
                     Name="Hallazgos" Type="String" />
             </SelectParameters>
         </asp:SqlDataSource>

And here is the Form:

 <asp:FormView ID="FormView_Proceso" runat="server" DataKeyNames="id"
    DataSourceID="SqlDataSource1" DefaultMode="Insert" >
            <InsertItemTemplate>
                nombreProceso:
                <asp:TextBox ID="nombreProcesoTextBox" runat="server" 
                    Text='<%# Bind("nombreProceso") %>' />
                analista_id:
                <asp:TextBox ID="analista_idTextBox" runat="server" 
                    Text='<%# Bind("analista_id") %>' />
                hallazgos:
                <asp:TextBox ID="hallazgosTextBox" runat="server" 
                    Text='<%# Bind("hallazgos") %>' />
                <asp:Button ID="InsertButton" runat="server" CausesValidation="True" 
                    CommandName="Insert" Text="Insert" />
                &nbsp;<asp:Button ID="InsertCancelButton" runat="server" 
                    CausesValidation="False" CommandName="Cancel" Text="Cancel" />
            </InsertItemTemplate>
        </asp:FormView>

I can't figure out out what's wrong. Any help is appreciated.

Upvotes: 2

Views: 1647

Answers (3)

tommylux
tommylux

Reputation: 89

Adding my comments for other googlers:

If you have different parameters for selecting and inserting and only want a few parameters to be inserted:

In GridViews its easier, you just set the column to be read-only

For FormViews, change the text labels from bind() to eval().

Upvotes: 0

Leonid
Leonid

Reputation: 3171

FormView (and other controls) implicitly tries to add parameter for every Bind instance, so you end up with four of them:
@Nombreproceso, @AnalistaID, @Hallazgos and @analista_id
You don't actually need these FormParameter's or (as it seems) explicit parameters at all, unless you want to override something (like type), but then <asp:Parameter ... is enough.
Also, you may break inside Inserting event of datasource and check command and parameters directly.

Upvotes: 2

abramlimpin
abramlimpin

Reputation: 5077

Your SelectCommand value should be different since the stored procedure StoredProcedure1 is already set to the InsertCommand.

Upvotes: 1

Related Questions