1 Function callStoredProcedure(sEmployeeID As String, Optional sNotes As String = "") As String
2 On Error GoTo errHand
3 Dim conn As ADODB.Connection
4 Set conn = "driver={SQL Server};server=(local);uid=sa;pwd=;database=pubs"
5
6 Dim adoComm As Object
7 Set adoComm = CreateObject("ADODB.Command") '创建一个对象,用来调用存储过程
8 With adoComm
9 .ActiveConnection = conn '设置连接
10 .CommandType = 4 '类型为存储过程,adCmdStoredProc = 4
11 .CommandText = "dbo.SP_BIG_CASE_REPORT" '存储过程名称
12 '.Parameters.Item("存储过程中参数的名称").Value = “值”
13 .Parameters.Item("@EmployeeID").Value = sEmployeeID '设置输入参数
14 .Parameters.Item("@Notes").Value = sNotes
15 .Execute '执行存储过程
16 End With
17 Set conn = Nothing
18
19 Exit Function
20 errHand:
21 MsgBox "callStoredProcedure Error : " & Err.Description, vbOKOnly + vbCritical, sApplicName
22 End Function