'引用Microsoft ActiveX Data Objects 2.1 Library Private Sub Command1_Click() '创建存储过程示例: Dim conn1 As ADODB.Connection Dim Rs As ADODB.Recordset Dim SQLServerConnect As String, SQLDrop As String, SQLCreate As String SQLServerConnect = "Driver={SQL Server};Server=TCL;Database=testaaa;" & _ "UID=sa;PWD=;" '连接字符串 Set conn1 = New ADODB.Connection conn1.ConnectionString = SQLServerConnect conn1.Open '判断存储过程是否存在,存在则先删除 SQLDrop = "if exists(select * from sysobjects where " & _ "id=object_id(N'dbo.pro_test') and objectproperty(id,N'IsProcedure')=1)" & _ "drop procedure dbo.pro_test" '创建存储过程 SQLCreate = "create proc pro_test(@InParam int,@OutParam int OUTPUT)" & vbCrLf & _ "as" & vbCrLf & "select @OutParam=@InParam+10" & vbCrLf & _ "SELECT * FROM AA WHERE AAid='1'" & vbCrLf & _ "return @OutParam" Set Rs = conn1.Execute(SQLDrop, 1, adCmdText) Set Rs = Nothing Set Rs = conn1.Execute(SQLCreate, 1, adCmdText) Set Rs = Nothing End Sub
Private Sub Command1_Click()
'创建存储过程示例:
Dim conn1 As ADODB.Connection
Dim Rs As ADODB.Recordset
Dim SQLServerConnect As String, SQLDrop As String, SQLCreate As String
SQLServerConnect = "Driver={SQL Server};Server=TCL;Database=testaaa;" & _
"UID=sa;PWD=;" '连接字符串
Set conn1 = New ADODB.Connection
conn1.ConnectionString = SQLServerConnect
conn1.Open
'判断存储过程是否存在,存在则先删除
SQLDrop = "if exists(select * from sysobjects where " & _
"id=object_id(N'dbo.pro_test') and objectproperty(id,N'IsProcedure')=1)" & _
"drop procedure dbo.pro_test"
'创建存储过程
SQLCreate = "create proc pro_test(@InParam int,@OutParam int OUTPUT)" & vbCrLf & _
"as" & vbCrLf & "select @OutParam=@InParam+10" & vbCrLf & _
"SELECT * FROM AA WHERE AAid='1'" & vbCrLf & _
"return @OutParam"
Set Rs = conn1.Execute(SQLDrop, 1, adCmdText)
Set Rs = Nothing
Set Rs = conn1.Execute(SQLCreate, 1, adCmdText)
Set Rs = Nothing
End Sub