vb如何执行sql server已经有的存储过程

2024-11-07 18:06:24
推荐回答(1个)
回答1:

'引用Microsoft ActiveX Data Objects 2.8 Library
Dim Cnn As ADODB.Connection
Dim Rs As ADODB.Recordset
Dim Cnn_c As New ADODB.Command
Dim cnn_p As ADODB.Parameter
Set Cnn = New ADODB.Connection
Set Rs = New ADODB.Recordset
'On Error Resume Next
Cnn.ConnectionString = ConnStr '连接字符陪返串
With Cnn
.CursorLocation = adUseClient
.Open '连接
End With
Set Cnn_c.ActiveConnection = Cnn
With Cnn_c
.CommandType = adCmdStoredProc '命令类型:存储过程
.CommandText = "AA" '存储过程高帆名
End With
Set cnn_p = Cnn_c.CreateParameter("ReTurn", adInteger, adParamReturnValue)
Cnn_c.Parameters.Append cnn_p '添加参数ReTurn(返回值)
Set Rs = Cnn_c.Execute '执行
MsgBox Rs.RecordCount '显示记录数
If Rs.RecordCount >芦念饥 0 Then
Rs.Close
End If
Cnn.Close
Set cnn_p = Nothing
Set Cnn_c = Nothing
Set Rs = Nothing
Set Cnn = Nothing