如何获得“返回值”从VB6中的存储过程

如何获得“返回值”从VB6中的存储过程

问题描述:

我有这个样本存储过程(如下),用于在表中插入数据。基本上,在此查询中,如果员工ID已存在,则不会插入数据。我的代码在VB6中工作正常,我能够使用存储过程插入记录,但我不知道如何检查记录是否已经存在。请帮我在VB6中怎么做。



I have this sample stored procedure(below) for inserting data in a table. Basically, in this query, it will NOT insert the data if the employee ID already exists. My code works fine in VB6, I was able to insert record using the stored proc, but I don't know how to check if the record already exists. Please help me how to do it in VB6.

ALTER PROCEDURE [dbo].[SP_EMPLOYEE_INSERT]
  @emp_id nvarchar(10)
 ,@emp_lname nvarchar(50)
 ,@emp_fname nvarchar(50)
 ,@emp_initial nvarchar(2)
 ,@emp_mngr_id nvarchar(10)
 ,@inputDt datetime

AS
BEGIN

IF NOT EXISTS (SELECT TOP (1) EmpID FROM EMPLOYEE WHERE EmpID = @emp_id)
    BEGIN
        INSERT INTO Employee
            (EmpID, Emp_Lastname, Emp_Firstname, Emp_MidInitial, EmpMngrID, InputDate)
        VALUES
            (@emp_id, @emp_lname,@emp_fname, @emp_initial, @emp_mngr_id, @inputDt)
        SET @emp_id = @@IDENTITY
    END

ELSE
    BEGIN
        SET @emp_id = (SELECT TOP (1) EmpID FROM EMPLOYEE WHERE EmpID = @emp_id)
        RETURN @emp_id
    END
END

这个提示可能对你有用将插入/更新合并到一个程序 [ ^ ]



我会放弃使用死语的强制性咆哮。
This tip may be of use to you Combining Insert/Update to one Procedure[^]

I will forgo the obligatory rant about using a dead language.