将存储过程中的输出变量值提取到调用程序

时间:2016-09-24 22:54:39

标签: sql-server vba stored-procedures

我正在尝试将sql存储过程的输出值提取到调用程序中。存储过程是:

ALTER  PROCEDURE  selectdediario (@descr varchar(20),@disp decimal output)
AS  
begin
   SET NOCOUNT ON;
   SELECT @disp = sum(disp)
   FROM diario
   WHERE descr = @descr;
  return
  end

我收到的输出是:

Stored Procedure: mala2.dbo.Selectdediario
Return Code = 0
Output Parameter(s): 
@disp = 676

我的visual basic子程序在vb6.0中:

Private Sub cmdApendTable_Click()
' declare the variable to to receive the output value of the procedure
Dim vdescr As String
vdescr = "gas sousa"

Dim vdisp As Currency

Call StartConnection

Set cmdEmpresa = New ADODB.Command
With cmdEmpresa
.Parameters.Append .CreateParameter("@descr", adVarChar, adParamInput, 20, vdescr)
.Parameters.Append .CreateParameter("@disp money OUTPUT", adCurrency, adParamoutput)

.ActiveConnection = conexao
.CommandType = adCmdStoredProc
.CommandText = "Selectdediario"
Set rsEmpresa = .Execute
 End With
 Debug.Print disp
End Sub

程序要求参数@disp所以我添加了0值。我希望将@disp的值放入我的程序中。

0 个答案:

没有答案