你可以使用 ADODB.Command 来调用存储过程,如: Dim adoComm As Object '// 创建一个对象,我们用来调用存储过程 Set adoComm = CreateObject("ADODB.Command") With adoComm '// 设置连接,假设 adoConn 为已经连接的 ADODB.Connection 对象 .ActiveConnection = adoConn '// 类型为存储过程,adCmdStoredProc = 4 .CommandType = 4 '// 存储过程名称 .CommandText = "你的存储过程名称" '// 设置输入参数 .Parameters.Item("@输入参数").Value = "值" '// 执行存储过程 .Execute If .Parameters.Item("@返回参数名称").Value = True Then Else End If End With '// 释放对象 Set adoComm = Nothing
Dim strPara As String Dim adoConn As ADODB.Connection Dim strCnn As String Dim Cmd As New ADODB.Command Dim Rst As New ADODB.Recordset Set adoConn = New ADODB.Connection strCnn = "Provider=sqloledb;Data Source=;Initial Catalog=;User Id=;Password=; " adoConn.Open strCnn adoConn.CursorLocation = adUseClient Cmd.ActiveConnection = adoConn Cmd.CommandText = "au_info" Cmd.CommandType = adCmdStoredProc Cmd.CommandTimeout = 0 Cmd.Parameters("@userid") = "1" Set Rst = Cmd.Execute If Rst.RecordCount = 0 Then Exit Sub Else Rst.MoveFirst MsgBox Rst.Fields("userid").Value, vbYesNo, "你好" End If adoConn.Close
'// 创建一个对象,我们用来调用存储过程
Set adoComm = CreateObject("ADODB.Command")
With adoComm
'// 设置连接,假设 adoConn 为已经连接的 ADODB.Connection 对象
.ActiveConnection = adoConn
'// 类型为存储过程,adCmdStoredProc = 4
.CommandType = 4
'// 存储过程名称
.CommandText = "你的存储过程名称"
'// 设置输入参数
.Parameters.Item("@输入参数").Value = "值"
'// 执行存储过程
.Execute If .Parameters.Item("@返回参数名称").Value = True Then Else End If
End With
'// 释放对象
Set adoComm = Nothing
Dim adoConn As ADODB.Connection
Dim strCnn As String
Dim Cmd As New ADODB.Command
Dim Rst As New ADODB.Recordset
Set adoConn = New ADODB.Connection
strCnn = "Provider=sqloledb;Data Source=;Initial Catalog=;User Id=;Password=; "
adoConn.Open strCnn
adoConn.CursorLocation = adUseClient
Cmd.ActiveConnection = adoConn
Cmd.CommandText = "au_info"
Cmd.CommandType = adCmdStoredProc
Cmd.CommandTimeout = 0
Cmd.Parameters("@userid") = "1"
Set Rst = Cmd.Execute
If Rst.RecordCount = 0 Then
Exit Sub
Else
Rst.MoveFirst
MsgBox Rst.Fields("userid").Value, vbYesNo, "你好"
End If
adoConn.Close