我的问题一样this。但我不理解解决方案。在我的SP参数" @ OperationType"确定什么是操作类型。(如果是1然后插入,如果是2然后更新,如果是3然后删除) 我的存储过程是这样的:
ALTER PROCEDURE [dbo].[JobOperation] (
@ID INT = NULL OUTPUT,
@JobTitle NVARCHAR(50) = NULL,
@JobLevel NVARCHAR(50) = NULL,
@Des NVARCHAR(MAX) = NULL,
@IsDbCommandCommitted BIT = 0 OUTPUT,
@DbCommitError VARCHAR(200) = NULL OUTPUT,
@OperationType INT = NULL,
@LanguageID INT = NULL
)
AS
IF @operationType = 1
BEGIN
BEGIN TRY
BEGIN TRANSACTION
INSERT INTO ....
SELECT @ID = MAX(ID)
FROM JOB
SET @IsDbCommandCommitted = 1
COMMIT TRANSACTION
END TRY
BEGIN CATCH
SET @DbCommitError = ERROR_MESSAGE()
ROLLBACK TRANSACTION
END CATCH
END
ELSE
IF @OperationType = 2
BEGIN
BEGIN TRY
BEGIN TRANSACTION
UPDATE JOB
......
SET @IsDbCommandCommitted = 1
COMMIT TRANSACTION
END TRY
BEGIN CATCH
SET @DbCommitError = ERROR_MESSAGE()
ROLLBACK TRANSACTION
END CATCH
END
ELSE
IF @OperationType = 3
BEGIN
BEGIN TRY
BEGIN TRANSACTION
DELETE
FROM JOB
WHERE ID = @ID
SET @IsDbCommandCommitted = 1
COMMIT TRANSACTION
END TRY
BEGIN CATCH
SET @DbCommitError = ERROR_MESSAGE()
ROLLBACK TRANSACTION
END CATCH
END
任何想法?