VB6.0 调用存储过程

时间:2023-12-17 10:47:08

最近有在做一个需求,需要在VB6.0中调用存储过程,整理了一下,供大家参考,

范例:

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