2
我有以下參數SQL SP ...ADODB不傳遞參數
myProc(@param1 AS TINYINT, @sparam2 AS TINYINT, @param3 AS TINYINT, @param4 AS
TINYINT, @param5 AS TINYINT, @param6 AS TINYINT, @param7 AS TINYINT, @paramOut
NVARCHAR (255) OUTPUT)
和我在VBA以下ADODB代碼...
sVal1 = 1
sVal2 = 1
sVal3 = 1
sVal4 = 1
sVal5 = 1
sVal6 = 1
sVal7 = 1
Dim cnn As ADODB.Connection
Dim cmd As ADODB.Command
Dim param1, param2, param3, param4, param5, param6, param7, param8 As
ADODB.Parameter
Dim Rs As ADODB.Recordset
Set cnn = New ADODB.Connection
cnn.ConnectionString = "DRIVER=SQL
Server;SERVER=SERVER;DATABASE=PEER_DB;Trusted_Connection=Yes"
cnn.Open cnn.ConnectionString
Set cmd = New ADODB.Command
Set Rs = New ADODB.Recordset
cmd.ActiveConnection = cnn
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "myProc"
Set param1 = cmd.CreateParameter("@param1", adTinyInt, adParamInput, 1, sVal1)
cmd.Parameters.Append param1
Set param2 = cmd.CreateParameter("@param2", adTinyInt, adParamInput, 1, sVal2)
cmd.Parameters.Append param2
Set param3 = cmd.CreateParameter("@param3", adTinyInt, adParamInput, 1, sVal3)
cmd.Parameters.Append param3
Set param4 = cmd.CreateParameter("@param4", adTinyInt, adParamInput, 1, sVal4)
cmd.Parameters.Append param4
Set param5 = cmd.CreateParameter("@param5", adTinyInt, adParamInput, 1, sVal5)
cmd.Parameters.Append param5
Set param6 = cmd.CreateParameter("@param6", adTinyInt, adParamInput, 1, sVal6)
cmd.Parameters.Append param6
Set param7 = cmd.CreateParameter("@param7", adTinyInt, adParamInput, 1,
adParamReturnValue)
cmd.Parameters.Append param7
Set param8 = cmd.CreateParameter("@paramOut", adVarChar, adParamOutput, 255,
adParamReturnValue)
cmd.Parameters.Append param8
Rs.CursorType = adOpenStatic
Rs.CursorLocation = adUseClient
Rs.LockType = adLockOptimistic
cmd.Execute
Rs.Open cmd
所有我試圖要做的是傳遞我的VBA sVal變量,並根據這些參數執行我的過程,然後我需要返回已經工作的輸出參數;該過程在使用ADODB連接時沒有正確執行,因爲我沒有得到我應該得到的結果。有人能引導我走向正確的方向嗎,我是否錯過了一些執行聲明?