存储过程如下
create proc sp_recordset
@bbb int
as
select * from aaa where bbb = @bbb
vb代码如下:
Dim cmd As ADODB.Command
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim ADOPrm
Set ADOPrm = New ADODB.Parameter
Set rs = New ADODB.Recordset
Set conn = New ADODB.Connection
conn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=DB_PurchaseOrder;Data Source=."
conn.Open
Set cmd = New ADODB.Command
cmd.CommandType = adCmdStoredProc
cmd.ActiveConnection = conn
cmd.CommandText = "sp_recordset"
Set ADOPrm = cmd.CreateParameter("@bbb", adInteger, adParamInput)
cmd.Parameters.Append ADOPrm
cmd.Parameters("@bbb").Value = "123"
Set rs = cmd.Execute()
MsgBox rs(0) & rs(1)