vb如何执行sql server已经有的存储过程
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
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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询