简体   繁体   English

该参数不作为存储过程参数存在

[英]Parameter does not exist as a stored procedure parameter

ALTER PROCEDURE [dbo].[SelectCompletionNonCompletionCourseReport]              
  @LearnerName   NVARCHAR(510) = NULL,              
  @ManagerId     INT = NULL,              
  @CourseId      INT = NULL,              
  @StartDateFrom SMALLDATETIME = NULL,              
  @StartDateTo   SMALLDATETIME = NULL,              
  @TeamList      XML = NULL,              
  @JobID         NVARCHAR(max)=NULL,              
  @CourseStatus  NVARCHAR(20)=NULL,      
  @ReportAdminID INT=0,      
  @ReportTeamList   NVARCHAR(max)=NULL,
  @RowsTotal int  = 0,
  @PageIndex int = 1,
  @RowsPerPage int = 10      
AS              
BEGIN              

  DECLARE @TblCrieiria TABLE              
    (              
       id         INT IDENTITY(1, 1),              
       areacode   NVARCHAR(11),              
       regioncode NVARCHAR(11),              
       teamcode   NVARCHAR(11)              
    )              
    IF @TeamList IS NULL              
    BEGIN              
    INSERT INTO @TblCrieiria VALUES(NULL,NULL,NULL)              
    END              

   BEGIN               

This is the beginning of the procedure... 这是程序的开始...

using (Database db = new Database(DScape.DAL.Config.ConfignPropertyName.DSCAPELMS_CONNECTION_STRING_NAME))
{
            var cmd = new SqlCommand
            {
                CommandText = "SelectCompletionNonCompletionCourseReport",
                CommandType = CommandType.StoredProcedure
            };

                cmd.Parameters.AddWithValue("@LearnerName", LearnerName);
                cmd.Parameters.AddWithValue("@ManagerId", ManagerId);
                cmd.Parameters.AddWithValue("@CourseId", CourseId);
                cmd.Parameters.AddWithValue("@StartDateFrom", StartDateFrom);
                cmd.Parameters.AddWithValue("@StartDateTo", StartDateTo);
                cmd.Parameters.AddWithValue("@TeamList", TeamList);
                cmd.Parameters.AddWithValue("@JobID", JobID);
                cmd.Parameters.AddWithValue("@CourseStatus", CourseStatus);
                cmd.Parameters.AddWithValue("@ReportAdminID", ReportAdminID);
                cmd.Parameters.AddWithValue("@ReportTeamList", ReportTeamList);
                cmd.Parameters.AddWithValue("@PageIndex", 1);

                DataSet dsClient = db.GetDataSet(cmd);
                if (dsClient.Tables.Count > 0)
                    return dsClient.Tables[0];
                else
                    return null;
        }

This is the method which communicates with the procedure, and it gaves me an error 这是与过程通信的方法,它给了我一个错误

Parameter does not exist as a stored procedure parameter/ function/procedure take too many arguments... 参数不存在,因为存储过程参数/函数/过程接受了太多参数...

It's about @PageIndex parameter. 关于@PageIndex参数。 Doesn't matter what is the value, we don't talk for values here but for parameter which is defined in the stored procedure but doesn't work? 值是什么都无所谓,我们这里不讨论值,而是讨论存储过程中定义但不起作用的参数?

And for the record, this problem did pop-up today w/o any code writing/modifying just appeared as I tried to do that report, when yesterday it was all good...I have a teammate which is next to me with absolute the same code both in sql and c# and it works just fine on his pc, but mine throws this errors, I'm trying to resolve this from 3 hours and I am completely out of answers , so please give me direction in which should I continue to resolve this ..................... 记录下来,这个问题今天确实弹出了,而我尝试编写该报告时却没有出现任何编写/修改代码,而昨天一切都很好……我旁边有一个队友,绝对在sql和c#中使用相同的代码,并且在他的PC上都可以正常工作,但是我抛出了此错误,我试图从3小时内解决此问题,而我完全没有答案,所以请给我指导继续解决这个问题.....................

and I say again, the problem is not from the connection to DB or type of the parameter or the value, the error is committed with the parameter itself - does not exist in the procedure, which is insane in my opinion. 我再说一遍,问题不是出自与DB的连接或参数或值的类型,错误是由参数本身造成的-在过程中不存在,在我看来这是疯狂的。

parameter count doesnt match. 参数计数不匹配。 check the params again. 再次检查参数。

You have to send parameters for rowstotal and rowsperpage as well because you have declared them at the top before "begin" clause. 您还必须发送rowstotal和rowsperpage的参数,因为您已经在“ begin”子句之前的顶部声明了它们。

If you do not want to send that params and they will be just constant, please declare them below as variable or constant, not a parameter. 如果您不希望发送该参数并且它们只是常量,请在下面将它们声明为变量或常量,而不是参数。

ie

CREATE PROCEDURE DeleteById
@TableName sysname, 
@Id int
AS
BEGIN
DECLARE @StrId AS VARCHAR(50)

SET @StrId = CONVERT(VARCHAR(50), @Id)

--any sp code here
END

Hope this helps. 希望这可以帮助。

Given that all parameters are optional, you are not required to explicitly provide any of them from your client code. 鉴于所有参数都是可选的,因此不需要从客户端代码中显式提供任何参数。 Default values will be provided for you by SQL Server. SQL Server将为您提供默认值。 The contract explictly states it in the stored procedure's signature. 合同在存储过程的签名中明确声明它。

An optional parameter is exactly that: optional. 可选参数正好是:可选。 If you had provided the incorrect number of parameters, SQL Server would have returned a different error, indicating that the number of parameters was incorrect. 如果提供的参数数量不正确,则SQL Server将返回另一个错误,表明参数数量不正确。 This is not the case. 不是这种情况。 Instead, you are seeing that you are asking for a parameter that is undefined, which indicates that the stored procedure signature you think you are calling does not match the stored procedure signature you are actually calling. 而是,您看到的是正在请求一个未定义的参数,该参数表明您认为正在调用的存储过程签名与实际调用的存储过程签名不匹配。

Verify that you are both connecting to the same database instance. 验证您连接到同一数据库实例。 If you are not, verify that the stored procedure is identical on both database instances. 如果不是,请验证两个数据库实例上的存储过程是否相同

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

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