简体   繁体   English

过程或函数指定了太多参数

[英]Procedure or function has too many arguments specified

I get an error 我收到一个错误

Procedure or function "myStoreProcNameHere" has too many arguments specified. 过程或函数“myStoreProcNameHere”指定了太多参数。

Below is my stored procedure and SqlDataSource . 下面是我的存储过程和SqlDataSource I'm using a GridView to edit data. 我正在使用GridView编辑数据。

Help? 救命? :( :(

Stored procedure: 存储过程:

ALTER PROCEDURE UpdateTwoTables 
    (@ID int, 
     @UserID varchar(10), 
     @Pass varchar(50), 
     @Enabled int, 
     @Permission int,
     @Rank int,
     @FName varchar(50),
     @LName varchar(50),
     @Phone varchar(50),
     @Email1 varchar(50),
     @Email2 varchar(50)
    ) 
AS
BEGIN TRANSACTION
    UPDATE tbl_user_login 
    SET UserID = @UserID, Pass = @Pass, 
        Enabled = @Enabled, Permission = @Permission, 
        Rank = @Rank 
    WHERE ID = @ID

    IF @@ERROR <> 0
    BEGIN
        ROLLBACK 
        RETURN
    END

    UPDATE tbl_user_profile 
    SET FName = @FName, LName = @LName, 
        Phone = @Phone, Email1 = @Email1, Email2 = @Email2 
    WHERE ID = @ID

    IF @@ERROR <> 0
    BEGIN
        ROLLBACK
        RETURN
    END

    COMMIT

ASP.NET SqlDataSource : ASP.NET SqlDataSource

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:DBConnString %>" 
        SelectCommand="SELECT tbl_user_login.ID, tbl_user_login.UserID, tbl_user_login.Pass, tbl_user_login.Enabled, tbl_user_login.Permission, tbl_user_login.Rank, tbl_user_profile.ID AS Expr1, tbl_user_profile.FName,
tbl_user_profile.LName, tbl_user_profile.Phone, tbl_user_profile.Email1, tbl_user_profile.Email2 FROM tbl_user_login INNER JOIN tbl_user_profile ON tbl_user_login.ID = tbl_user_profile.ID" 
        UpdateCommand="UpdateTwoTable" UpdateCommandType="StoredProcedure">
        <UpdateParameters>
            <asp:Parameter Name="ID" />
            <asp:Parameter Name="UserID"/>
            <asp:Parameter Name="Pass"/>
            <asp:Parameter Name="Enabled"/>
            <asp:Parameter Name="Permission"/>
            <asp:Parameter Name="Rank"/>
            <asp:Parameter Name="FName"/>
            <asp:Parameter Name="LName"/>
            <asp:Parameter Name="Phone"/>
            <asp:Parameter Name="Email1"/>
            <asp:Parameter Name="Email2"/>
        </UpdateParameters>        
    </asp:SqlDataSource>

I've ran into this error message before when I was calling a stored procedure from within a loop (foreach). 在我从循环(foreach)中调用存储过程之前,我遇到过此错误消息。

The cause of the exception that I received was due to the fact that I wasn't clearing the Parameter's after each iteration of the loop. 我收到的异常的原因是由于我在循环的每次迭代后没有清除参数。

For example: This code throws: 例如:此代码抛出:

using (SqlCommand cmd = new SqlCommand())
{
    cmd.CommandType = System.Data.CommandType.StoredProcedure;
    cmd.CommandText = "MySproc";
    foreach (MyClass c in myClasses)
    {
        cmd.Parameters.AddWithValue("@val1", c.val1);
        cmd.Parameters.AddWithValue("@val2", c.val2);
        var result = MyDbManager.instance.ExecuteScalarQuery(cmd);
    }
}

The fix was to clear the parameters: 修复是清除参数:

using (SqlCommand cmd = new SqlCommand())
{
    cmd.CommandType = System.Data.CommandType.StoredProcedure;
    cmd.CommandText = "MySproc";
    foreach (MyClass c in myClasses)
    {
        cmd.Parameters.AddWithValue("@val1", c.val1);
        cmd.Parameters.AddWithValue("@val2", c.val2);
        var result = MyDbManager.instance.ExecuteScalarQuery(cmd);
        cmd.Parameters.Clear();
    }
}

Must of instance Create 必须是实例创建

Vb.Net & C# Vb.Net&C#

glopal value glopal值

vb.net -> Dim cmd as New SqlCommand()

c#-> Sqlcommand cmd=new sqlCommand()

Con.open()

cmd=New SqlCommand()

something write...

Con.Close()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM