|
本帖最后由 superlsf 于 2018-8-9 11:51 编辑
sql server中一个存储过程本身运行正常,但在VBA中调用时,运行过程本身没报错,但没正常结果返回
- Sub 多参数的存储过程()
- Dim strSQL As String
- Dim i As Long
- If conn Is Nothing Then Connect
- If conn.State = 0 Then conn.Open
-
- ' execute dbo.proc_jggz @as_odr_no = :as_odr_no,
- ' @as_pur_no = :as_pur_no,
- ' @as_date_start = :as_date_start,
- ' @as_date_end = :as_date_end,
- ' @as_vendermid = :as_vendermid,
- ' @as_style = :as_style,
- ' @as_contract_no = :as_contract_no,
- ' @as_matno = :as_matno,
- ' @as_matsx = :as_matsx,
- ' @unit = :as_unit,
- ' @ls_baozhuang = :ls_baozhuang
- cmd.ActiveConnection = conn
- cmd.CommandType = adCmdStoredProc
- 'cmd.Prepared = True
- cmd.commandText = "proc_jggz " '存储过程的名称
- cmd.Parameters.Append cmd.CreateParameter("as_odr_no", adVarWChar, adParamInput, 16, "")
- cmd.Parameters.Append cmd.CreateParameter("as_pur_no", adVarWChar, adParamInput, 256, "")
- cmd.Parameters.Append cmd.CreateParameter("as_date_start", adVarWChar, adParamInput, 10, "2018-08-01")
- cmd.Parameters.Append cmd.CreateParameter("as_date_end", adVarWChar, adParamInput, 10, "2018-08-08")
- cmd.Parameters.Append cmd.CreateParameter("as_vendermid", adVarWChar, adParamInput, 8, "")
- cmd.Parameters.Append cmd.CreateParameter("as_style", adVarWChar, adParamInput, 16, "")
- cmd.Parameters.Append cmd.CreateParameter("as_contract_no", adVarWChar, adParamInput, 64, "")
- cmd.Parameters.Append cmd.CreateParameter("as_matno", adWChar, adParamInput, 26, "")
- cmd.Parameters.Append cmd.CreateParameter("as_matsx", adVarWChar, adParamInput, 1, "")
- cmd.Parameters.Append cmd.CreateParameter("unit", adVarWChar, adParamInput, 8, "")
- cmd.Parameters.Append cmd.CreateParameter("ls_baozhuang", adVarWChar, adParamInput, 8, "")
-
- ' cmd.Parameters.Refresh
- ' For i = 0 To cmd.Parameters.Count - 1
- ' Debug.Print cmd.Parameters(i).Name, cmd.Parameters(i).Type, cmd.Parameters(i).Direction
- ' Next
- ' ActiveSheet.Range("A1").CopyFromRecordset cmd.Execute
- cmd.Execute
-
- '语法 recordset.Open Source, ActiveConnection, CursorType, LockType, Options
- rst.Open cmd, , adOpenStatic, adLockBatchOptimistic ', adCmdStoredProc
- Sheet1.Cells.Clear
- If Not rst.EOF Then
- For i = 0 To rst.Fields.Count - 1
- Sheet1.Cells(1, i + 1).Value = rst.Fields(i).Name
- Next
- Sheet1.Cells(2, 1).CopyFromRecordset rst
- End If
- rst.Close
- conn.Close
- End Sub
复制代码
|
|