将参数传递给存储过程

时间:2012-07-12 15:40:02

标签: ms-access vba access-vba

以下代码返回带有硬编码值的存储过程。我需要允许74(存储过程中的@catcode)更改为从组合框中选择的任何内容。任何帮助是极大的赞赏。我在Access中使用传递查询。

Private Sub ok_Click()

Dim objConnection As New ADODB.Connection

Dim objCom As ADODB.Command

Dim provStr As String

Dim objConnection As New ADODB.Connection

Dim objCom As ADODB.Command

Dim provStr As String

Set objCom = New ADODB.Command

objConnection.Provider = "sqloledb"

provStr = "Data Source=***;" & "Initial Catalog=***;User Id=***;Password=***;"

objConnection.Open provStr


With objCom

.ActiveConnection = objConnection

.CommandText = "dbo.ix_spc_planogram_match " & ("@catcode=") & Me.cat_code.Value

.CommandType = adCmdStoredProc

.Parameters.Refresh     

.Parameters("@catcode").Value = me.cat_code.value 
   .Execute

    End With

    End Sub

存储过程:

execute dbo.ix_spc_planogram_match @catcode

1 个答案:

答案 0 :(得分:0)

我想你在这些方面意味着什么:

.CommandText = "dbo.ix_spc_planogram_match " &  me.cat_code
.CommandType = adCmdStoredProc
.cmd.Parameters("@catcode") =  me.cat_code

.Execute

这假设组合的绑定列包含所需的值。