开发者

Error with Stored Procedure (parameter related)

开发者 https://www.devze.com 2023-04-10 10:09 出处:网络
i have a stored procedure that i tested directly and it works, but when i call it from code i get the error:

i have a stored procedure that i tested directly and it works, but when i call it from code i get the error:

"Procedure or function editItem has too many arguments specified"

Can someone please tell me why this error happens? Is it because my sqlDataSource is passing parameters from BIND that the stored procedure does,t need? I thought extra parameters where just ignored by the stored procedures.

Thanks

Edit: Here is some more info about the problem. Its got me baffled. Basically, i got a bunch of items added to the templates like so:

                           <EditItemTemplate>
                            <asp:TextBox runat="server" ID="tbEditItemDescription" Text='<%# Bind("itemDescription") %>'></asp:TextBox>
                        </EditItemTemplate>

Now as far as i know, Bind supplies the parameter automatically. I also have 5 parameters i added manually, like so:

                <UpdateParameters>
                    <asp:ControlParameter DbType="Int16" Name="itemTypeId" ControlID="dvIndividualItem$ddlItemTypes"
                        PropertyName="SelectedValue" />
                    <asp:ControlParameter DbType="Int16" Name="itemSubTypeId" ControlID="dvIndividua开发者_StackOverflow社区lItem$ddlItemSubTypes"
                        PropertyName="SelectedValue" />
                    <asp:ControlParameter DbType="Int64" Name="itemSubSubTypeId" ControlID="dvIndividualItem$ddlItemSubSubTypes"
                        PropertyName="SelectedValue" />
                    <asp:ControlParameter DbType="Int16" Name="numberOfTurns" ControlID="dvIndividualItem$tbEditEffectTurns"
                        PropertyName="Text" />
                    <asp:ControlParameter DefaultValue="0" DbType="Int64" Name="itemId" ControlID="gvItems"
                        PropertyName="SelectedDataKey.Value" />

Now when i debugged the sql data source, i found that it actually only has 5 parameters (the ones i added manually). How is it possible, that it is giving me an error of having too many parameters, when it infact has LESS parameters than it needs? Or am i just looking in the wrong place? I looked in UpdateParameters ==> base ==> count, which contains 5.

Thanks for the help.


Quite simply, you are sending in more arguments than the procedure is expecting.

Procedure with 3 parameters:

ALTER PROCEDURE [dbo].[GetData](
    @Arg1 VARCHAR(50),
    @Arg2 VARCHAR(50),
    @Arg3 VARCHAR(50)
)AS

Code with 4 parameters:

cmd.Parameters.Add("@Arg1", SqlDbType.VarChar).Value = "Arg1"; 
cmd.Parameters.Add("@Arg2", SqlDbType.VarChar).Value = "Arg2"; 
cmd.Parameters.Add("@Arg3", SqlDbType.VarChar).Value = "Arg3"; 
cmd.Parameters.Add("@Arg4", SqlDbType.VarChar).Value = "Arg4"; 

//execute = BANG! Procedure is not expecting @Arg4
0

精彩评论

暂无评论...
验证码 换一张
取 消