1

Excel 2007 VBA를 통해 ADO를 사용하여 저장 프로 시저 (SQL Server 2008)를 실행하려고합니다. 저장 프로 시저를 실행하면, 다음과 같은 오류가 발생하고있어 : Procedure or function 'crl_GetData' expects parameter '@StartDate', which was not supplied.저장 프로 시저를 실행할 때 매개 변수가 제공되지 않음

를 I 그래서 같이 ADODB.Command 방법을 이용하여 파라미터를 제공하고있다 :

Public Function fGetMI(strStart As String, strEnd As String) As ADODB.Recordset 

Dim oDB As ADODB.Connection: Set oDB = New ADODB.Connection 
Dim oCM As ADODB.Command: Set oCM = New ADODB.Command 
Dim oRS As ADODB.Recordset 

oDB.Open gcConn 

With oCM 
    .ActiveConnection = oDB 
    .CommandType = adCmdStoredProc 
    .CommandText = "crl_GetData" 
    .Parameters.Append .CreateParameter("@StartDate", adDate, adParamInput, , strStart) 
    .Parameters.Append .CreateParameter("@EndDate", adDate, adParamInput, , strEnd) 
    Set oRS = .Execute 'Error thrown here' 
End With 

If Not oRS.BOF And Not oRS.EOF Then 
    Set fGetMI = oRS 
End If 

oRS.Close 
Set oRS = Nothing 
oDB.Close 
Set oDB = Nothing 

End Function 

에러 라인 Set oRS = .Execute에 수신된다.

저장 프로 시저가 @EndDate 매개 변수와 저장 프로 시저와 함께 @StartDate 매개 변수를 필요는과 같이 정의된다 :

CREATE PROCEDURE [dbo].[crl_GetData] 
    @TL varchar(128) = null, 
    @Unit varchar(16) = null, 
    @Site varchar(16) = null, 
    @OutcomeId int = null, 
    @Auth varchar(128) = null, 
    @StartDate datetime, 
    @EndDate datetime 
AS 
    BEGIN 
     SELECT 
      [Claim Handler], 
      [Team Leader], 
      [Unit], 
      [Site], 
      [Claim Reference], 
      [Outcome], 
      [Authoriser], 
      [Date] 

     FROM 
      crl_all_data 

     WHERE 
      [Date] BETWEEN @StartDate AND @EndDate 
      AND (@TL IS NULL OR ([TL_ID] = @TL)) 
      AND (@Unit IS NULL OR ([Unit] = @Unit)) 
      AND (@Site IS NULL OR ([Site] = @Site)) 
      AND (@OutcomeId IS NULL OR ([OUTCOME_ID] = @OutcomeId)) 
      AND (@Auth IS NULL OR ([AUTH_ID] = @Auth)) 

     ORDER BY 
      [Date] ASC 

     OPTION(RECOMPILE); 
    END 

GO 
나는이 방법을 사용했습니다으로

사람이 오류가 발생하는 이유에 관해서는 도와 드릴까요 이전에 여러 번 스토어드 프로 시저를 실행 했습니까? 그렇지 않으면 실제 위치에 의해 전달되는 것,

oCM.NamedParameters = True 

매개 변수를 지정하기 전에 :

답변

2

당신은 추가해야합니다.

관련 문제