在VB中执行时存储过程获取错误 [英] Stored procedure getting error's when executing in VB
本文介绍了在VB中执行时存储过程获取错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hi我的存储过程从VB执行时出错执行后的事务计数表示Begin和Commit状态不匹配,previouse count = 0,current count = 1,
我尝试过:
Hi My Stored procedure is getting errors when executing from VB " Transaction count after Execute indicates a mismatching of Begin and Commit statments, previouse count =0, current count =1,
What I have tried:
ALTER PROCEDURE [dbo].[SMlineUpdate3]
(
@id [int],
@Payroll_Id [int],
@ProductCode nvarchar(255),
@Description nvarchar (255),
@Qty nvarchar(255)
)
AS
IF EXISTS(SELECT Id from Smline where @id = Id)
DECLARE @User INT
BEGIN TRANSACTION
Update dbo.SmLine
Set [Payroll_Id]= @Payroll_Id
,ProductCode= @ProductCode
,Description = @Description
,Qty = @Qty
Where [Id]=@Id
IF @@ERROR <> 0
BEGIN
ROLLBACK
RETURN
END
ELSE
BEGIN TRANSACTION
DECLARE @SId INT
INSERT INTO SmLine ([Payroll_Id],[ProductCode],[Description],[Qty]) VALUES (@Payroll_Id,@ProductCode ,@Description,@Qty)
SET @SId= SCOPE_IDENTITY()
IF @@ERROR <> 0
BEGIN
ROLLBACK
RETURN
END
COMMIT
推荐答案
在sp的开头有一个BEGIN,在ELSE的开头有一个BEGIN,底部只有一个COMMIT。或者在ELSE中提交一个,或者删除ELSE中的那个BEGIN,以符合您的要求为准。
You have a BEGIN at the start of the sp and a BEGIN at the start of the ELSE and only one COMMIT at the bottom. Either COMMIT the one inside the ELSE or remove the BEGIN for the one in the ELSE, whichever suits your requirements.
这篇关于在VB中执行时存储过程获取错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文