如何从存储过程中获取值

Gop*_*pal 1 sql sql-server vb6

如何使用VB6和从存储过程获取返回值SQL Server。

存储过程

ALTER PROCEDURE [dbo].[DayAttn]
    @Attn VARCHAR(12) OUTPUT
AS
BEGIN
    SELECT @Attn = MAX(id)
    FROM   table1

    RETURN @Attn
END
Run Code Online (Sandbox Code Playgroud)

VB6

conn.Execute "exec DayAttn '" '" & Attn & "'"
Run Code Online (Sandbox Code Playgroud)

上面的代码显示错误。

Joh*_*nFx 6

此代码应该向您展示如何在 VB6/ADO classic 中执行此操作:

Set cmdTemp = New ADODB.Command
Set cmdTemp.ActiveConnection = gcnxMain
cmdTemp.Parameters.Append cmdTemp.CreateParameter("Ret", adInteger, adParamReturnValue)
cmdTemp.CommandType = adCmdStoredProc
cmdTemp.CommandText = "Procname"
cmdTemp.Execute
MsgBox "Return Value: " & cmdTemp.Parameters("Ret")
Run Code Online (Sandbox Code Playgroud)