# 自问自答

Posted by Joint on October 22, 1999 at 00:45:56:

In Reply to: 请问ADO物件如何传参数给stored procedures posted by Joint on October 21, 1999 at 17:55:16:

已经try出来了
这和一般带有参数的方法相同.
或许你们可以参考看看,
不是每一本书都有的哦!!

Private Sub Command1_Click()
Dim db As Connection
Dim cmd As New ADODB.Command
Set db = New Connection
Dim Param As ADODB.Parameter
Set Param = cmd.CreateParameter("prmBID1", adVarChar, adParamInput, 20)
cmd.Parameters.Append Param
cmd.Parameters("prmBID1").Value = "1"
Set Param = cmd.CreateParameter("prmBID2", adVarChar, adParamInput, 20)
cmd.Parameters.Append Param
cmd.Parameters("prmBID2").Value = "2"
db.CursorLocation = adUseClient
db.Open "PROVIDER=MSDASQL;dsn=GDMS_sql;uid=sa;pwd=;"
Set cmd.ActiveConnection = db
Set adoPrimaryRS = New Recordset
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "myproc1"
Set adoPrimaryRS = cmd.Execute
Set grdDataGrid.DataSource = adoPrimaryRS

End Sub

Follow Ups: