如何获得“返回值”从VB6中的存储过程 [英] How to get the "return value" from stored procedure in VB6

查看:193
本文介绍了如何获得“返回值”从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.


这篇关于如何获得“返回值”从VB6中的存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆