in/out パラメータも使用する方法は次のとおりです。
サンプル ストアド プロシージャ
CREATE PROCEDURE [dbo].[TestRetVal]
@P1 int, --Parameter 1, INPUT ONLY
@P2 int OUT --Parameter 2, INPUT/OUTPUT
AS
BEGIN
DECLARE @RetVal int
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SET @RetVal = @P1 + @P2 --Do whatever you need with parms
SET @P2 = 10 * @P1 --Assign value to OUTPUT parameter
RETURN @RetVal --Assign SP return value
END
VB6 コード:
Dim cnnDB As ADODB.Connection
Dim Cmd As New ADODB.Command
Dim Param As ADODB.Parameter
'Set up your cnnDB connection...
Cmd.CommandText = "TestRetVal"
Cmd.CommandType = CommandTypeEnum.adCmdStoredProc
Set Param = Cmd.CreateParameter(, adInteger, adParamReturnValue)
Cmd.Parameters.Append Param
Set Param = Cmd.CreateParameter("P1", adInteger, adParamInput, 8, 2)
Cmd.Parameters.Append Param
Set Param = Cmd.CreateParameter("P2", adInteger, adParamInputOutput, 8, 4)
Cmd.Parameters.Append Param
'Assuming a connection has been established
Set Cmd.ActiveConnection = cnnDB
Set rstTest = Cmd.Execute()
Debug.Print Cmd.Parameters(0) '--> 6 (Shows SP return value, value of the FIRST parameter added to cmd)
Debug.Print Cmd.Parameters("P2") '--> 20 (Shows current value for P2 OUT parameter)
ストアドプロシージャの戻り値を取得する方法も参照してください(ペコスビルに感謝します!)