如果sql的存储过程需要接受一个参数
可以用Set Parameter = Command.CreateParameter("aa", adVarChar, adParamInput, 10, 11)
CreateParameter这样想里面传递参数。
可是存储过程需要接受两个或多个参数怎么向里面传递参数???

解决方案 »

  1.   

    传参的例子,注意IN与OUT On Error GoTo err:
       cmd.CommandText = "Att_CalCulateEmp"
       cmd.CommandType = adCmdStoredProc
       cmd.ActiveConnection = Cn
       cmd.Parameters.Append cmd.CreateParameter("empid", adInteger, adParamInput, , Empid)
       cmd.Parameters.Append cmd.CreateParameter("startdate", adDate, adParamInput, , EmpRundate)
       cmd.Parameters.Append cmd.CreateParameter("totaltime", adInteger, adParamOutput)
       cmd.Parameters.Append cmd.CreateParameter("id", adInteger, adParamOutput)
       cmd.Execute
       Set cmd = Nothing
       Exit Sub
    err:
       MsgBox err.Description
      

  2.   

    --你可以这样改一下  On Error GoTo err:
      'Dim cmd As New ADODB.Command
      Set cmd.ActiveConnection = cn
      With cmd
            .CommandType = adCmdStoredProc
            .CommandText = "Att_CalCulateEmp"
            .Parameters(1) = "参数1"
            .Parameters(1) = "参数2"
            .Parameters(1) = "参数3"
            '.Parameters(n) = "参数n"
      End With
      cmd.Execute
      Exit Sub
    err:
       MsgBox err.Description
      

  3.   

    我借用GGL123() 的说一下
      On Error GoTo err:
      'Dim cmd As New ADODB.Command
      Set cmd.ActiveConnection = cn
      With cmd
            .CommandType = adCmdStoredProc
            .CommandText = "Att_CalCulateEmp"
            .Parameters(1) = "参数1"
            .Parameters(2) = "参数2"
            .Parameters(3) = "参数3"
            '.Parameters(n) = "参数n"
      cmd.Execute
      x = cmd.parameters(n+1)  '假设x是已声明的变量,在这里接受返回的参数,n+1是返回参数在存储过程
                   '参数集合中的排序位置...
     End With
      Exit Sub
    err:
       MsgBox err.Description