1
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. 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 .....................

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.

4

2 回答 2

0

参数计数不匹配。再次检查参数。

您还必须为 rowstotal 和 rowsperpage 发送参数,因为您已经在“begin”子句之前在顶部声明了它们。

如果您不想发送该参数并且它们只是常量,请在下面将它们声明为变量或常量,而不是参数。

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

希望这可以帮助。

于 2013-10-14T16:38:46.703 回答
0

鉴于所有参数都是可选的,您不需要从客户端代码中显式提供任何参数。SQL Server 将为您提供默认值。合同在存储过程的签名中明确说明了这一点。

一个可选参数就是:可选的。如果您提供的参数数量不正确,SQL Server 将返回不同的错误,表明参数数量不正确。不是这种情况。相反,您看到您正在请求一个未定义的参数,这表明您认为您正在调用的存储过程签名与您实际调用的存储过程签名不匹配。

验证您是否连接到同一个数据库实例。如果不是,请验证两个数据库实例上的存储过程是否相同。

于 2013-10-14T18:00:57.837 回答