过程或函数SP_XXX具有指定的参数太多(Procedure or function SP_XXX

2019-07-30 07:01发布

IM工作的一些项目,并得到这个错误信息:

*过程或函数SP_XXX具有指定*以下是我的SQL参数IM通过ASP C#应用程序检查许多网站和没有什么:)非常感谢你的帮助的参数太多!

        cmd.Parameters.Add(new SqlParameter() { Value = user.CODE, ParameterName = "@CODE" });cmd.Parameters.Add(new SqlParameter() { Value = CODE, ParameterName = "@OLD_CODE" });
        cmd.Parameters.Add(new SqlParameter() { Value = COCODE, ParameterName = "@OLD_COCODE" });
        cmd.Parameters.Add(new SqlParameter() { Value = user.COCODE, ParameterName = "@COCODE" });
        cmd.Parameters.Add(new SqlParameter() { Value = user.MEMBERTYPE, ParameterName = "@MEMBERTYPE" });
        cmd.Parameters.Add(new SqlParameter() { Value = user.ENNAME, ParameterName = "@ENNAME" });
        cmd.Parameters.Add(new SqlParameter() { Value = user.ARNAME, ParameterName = "@ARNAME" });
        cmd.Parameters.Add(new SqlParameter() { Value = user.NATIONALITY, ParameterName = "@NATIONALITY" });
        cmd.Parameters.Add(new SqlParameter() { Value = user.GENDER, ParameterName = "@GENDER" });
        cmd.Parameters.Add(new SqlParameter() { Value = user.SPECIAL, ParameterName = "@SPECIAL" });
        cmd.Parameters.Add(new SqlParameter() { Value = (object)user.BIRTHDATE ?? DBNull.Value, ParameterName = "@BIRTHDATE" });
        cmd.Parameters.Add(new SqlParameter() { Value = user.Religion, ParameterName = "@RELIGION" });
        cmd.Parameters.Add(new SqlParameter() { Value = user.QUALIFY, ParameterName = "@QUALIFY" });
        cmd.Parameters.Add(new SqlParameter() { Value = user.MEMBERPOS, ParameterName = "@MEMBERPOS" });
        cmd.Parameters.Add(new SqlParameter() { Value = (object)user.JOINDATE ?? DBNull.Value, ParameterName = "@JOINDATE" });
        cmd.Parameters.Add(new SqlParameter() { Value = (object)user.EXPIRYDATE ?? DBNull.Value, ParameterName = "@EXPIRYDATE" });
        cmd.Parameters.Add(new SqlParameter() { Value = user.POBOX, ParameterName = "@POBOX" });
        cmd.Parameters.Add(new SqlParameter() { Value = user.WORKTEL, ParameterName = "@WORKTEL" });
        cmd.Parameters.Add(new SqlParameter() { Value = user.HOMETEL, ParameterName = "@HOMETEL" });
        cmd.Parameters.Add(new SqlParameter() { Value = user.MOBILE, ParameterName = "@MOBILE" });
        cmd.Parameters.Add(new SqlParameter() { Value = user.FAX, ParameterName = "@FAX" });
        cmd.Parameters.Add(new SqlParameter() { Value = user.EMAIL, ParameterName = "@EMAIL" });
        cmd.Parameters.Add(new SqlParameter() { Value = user.WEBSITE, ParameterName = "@WEBSITE" });
        cmd.Parameters.Add(new SqlParameter() { Value = user.ACCCODE, ParameterName = "@ACCCODE" });

        cmd.Parameters.Add(new SqlParameter() { Value = user.AMOUNT, ParameterName = "@AMOUNT" });
        cmd.Parameters.Add(new SqlParameter() { Value = user.PAIDAMOUNT, ParameterName = "@PAIDAMOUNT" });
        cmd.Parameters.Add(new SqlParameter() { Value = user.EMIRATE, ParameterName = "@EMIRATE" });
        cmd.Parameters.Add(new SqlParameter() { Value = user.MILIT_NO, ParameterName = "@MILIT_NO" });
        cmd.Parameters.Add(new SqlParameter() { Value = user.GRADE, ParameterName = "@GRADE" });

        //need job

        cmd.Parameters.Add(new SqlParameter() { Value = user.NEEDJOB, ParameterName = "@NEEDJOB" });
        cmd.Parameters.Add(new SqlParameter() { Value = user.DEBIT, ParameterName = "@DEBIT" });
        cmd.Parameters.Add(new SqlParameter() { Value = user.JOBNAME, ParameterName = "@JOBNAME" });
        cmd.Parameters.Add(new SqlParameter() { Value = user.BNKNAME, ParameterName = "@BNKNAME" });
        cmd.Parameters.Add(new SqlParameter() { Value = (object)user.BNKAMOUNT ?? DBNull.Value, ParameterName = "@BNKAMOUNT" });
        cmd.Parameters.Add(new SqlParameter() { Value = user.COMPAGNY, ParameterName = "@COMPAGNY" });
        cmd.Parameters.Add(new SqlParameter() { Value = (object)user.COMPAMOUNT ?? DBNull.Value, ParameterName = "@COMPAMOUNT" });
        cmd.Parameters.Add(new SqlParameter() { Value = user.PRSN, ParameterName = "@PRSN" });
        cmd.Parameters.Add(new SqlParameter() { Value = (object)user.PRSNAMOUNT ?? DBNull.Value, ParameterName = "@PRSNAMOUNT" });
        if (user.PIC == null)
            cmd.Parameters.Add(new SqlParameter() { Value = DBNull.Value, ParameterName = "@PIC", SqlDbType = System.Data.SqlDbType.Image });
        else
            cmd.Parameters.Add(new SqlParameter() { Value = user.PIC, ParameterName = "@PIC" });
        cmd.Parameters.Add(new SqlParameter() { Value = user.COMPANY, ParameterName = "@COMPANY" });
        cmd.Parameters.Add(new SqlParameter() { Value = user.TYPEBLOOD, ParameterName = "@TYPEBLOOD" });
        cmd.Parameters.Add(new SqlParameter() { Value = user.PASSPORTNUM, ParameterName = "@PASSPORTNUM" });
        cmd.Parameters.Add(new SqlParameter() { Value = user.LEAVENUM, ParameterName = "@LEAVENUM" });
        cmd.Parameters.Add(new SqlParameter() { Value = user.POSBEFORE, ParameterName = "@POSBEFORE" });
 cmd.Parameters.Add(new SqlParameter() { Value = (object)user.LEAVEDATE ?? DBNull.Value, ParameterName = "@LEAVEDATE" });
        cmd.CommandType = System.Data.CommandType.StoredProcedure;
        cmd.CommandText = "SP_MSMEMBERS_UPDATE";
        cmd.Connection = con;
        string constr = ConfigurationManager.ConnectionStrings["ConnectionStrings"].ToString();
        con.ConnectionString = constr;
        con.Open();
        int x = cmd.ExecuteNonQuery();

        con.Close();

    ALTER PROCEDURE [dbo].[SP_MSMEMBERS_UPDATE] 
       (
 @CODE VARCHAR(10),
 @OLD_CODE VARCHAR(10),
 @COCODE INTEGER,
 @OLD_COCODE INTEGER,
 @MEMBERTYPE INTEGER,
 @ENNAME VARCHAR(40),
 @ARNAME VARCHAR(40),
 @NATIONALITY INTEGER,
 @GENDER VARCHAR(1),
 @SPECIAL VARCHAR(1),
 @BIRTHDATE DATETIME,
 @RELIGION INTEGER,
 @QUALIFY INTEGER,
 @MEMBERPOS VARCHAR(40),
 @JOINDATE DATETIME,
 @EXPIRYDATE DATETIME,
 @POBOX VARCHAR(15),
 @WORKTEL VARCHAR(30),
 @HOMETEL VARCHAR(30),
 @MOBILE  VARCHAR(30),
 @FAX  VARCHAR(30),
 @EMAIL VARCHAR(40),
 @WEBSITE VARCHAR(80),
 @ACCCODE VARCHAR(20),
 @AMOUNT NUMERIC(15,3),
 @PAIDAMOUNT NUMERIC(15,3),
 @EMIRATE INTEGER,
 @MILIT_NO VARCHAR(40),
 @GRADE VARCHAR(20)
 --new add
 ,@NEEDJOB VARCHAR(1) 
 ,@DEBIT VARCHAR(1)
 ,@JOBNAME varchar(20)
 ,@BNKNAME varchar(25)
 ,@BNKAMOUNT NUMERIC(15,3)
 ,@COMPAGNY nvarchar(25)
 ,@COMPAMOUNT NUMERIC(15,3)
 ,@PRSN varchar(30)
 ,@PRSNAMOUNT NUMERIC(15,3)
 ,@PIC image
 ,@COMPANY varchar(25)
 ,@TYPEBLOOD varchar(20)
 ,@PASSPORTNUM varchar(20)
 ,@LEAVENUM varchar(10)
 ,@POSBEFORE varchar(15)
 ,@LEAVEDATE datetime
)

Answer 1:

对不起,错后

所有第二,我跑的C#代码如下所示:

public class MemberD
{
    public SqlCommand cmd = new SqlCommand();
    public SqlConnection con = new SqlConnection("ConStr");
    public SqlDataReader dr;

    public void UpdateMember(string CODE, int COCODE, Member user)
    {
        cmd.Parameters.Clear(); // Here's  the solution

        //Here I added my SQL parameters 
        cmd.CommandType = System.Data.CommandType.StoredProcedure;
        cmd.CommandText = "SP_MSMEMBERS_UPDATE";
        cmd.Connection = con;
        con.Open();
        cmd.ExecuteNonQuery();

        con.Close();
    }
}

问题的关键是使用的SqlCommand作为全局变量初始化一次,所以当我使用Update方法两次或两次GetByID方法例如,SqlCommand的变量保持旧的参数,以及,即时通讯。 所以,当你传递参数超过SP需要你得到上面的错误,所以干脆我说:cmd.Parameters.Clear(); 在每个方法的开始。

现在它的工作的罚款。



Answer 2:

该错误通常代表比你的SP已经定义了多个参数。

由于您没有提供足够的代码来告诉你肯定(提供更多的CMD代码块和至少SP的定义),我会假设它是这种情况。 特别是随着供应这么多的争论。

我看过,这也可与SqlDatasources打交道时所引起的潜在问题。 然而,由于提供的有限的代码,我只是指出这一点的可能性。



文章来源: Procedure or function SP_XXX has too many arguments specified