我的問題相同this。但我不明白solution.in我的SP參數「@OperationType」確定什麼是操作類型(如果1然後插入,如果2然後更新,如果3然後刪除) 我的存儲程序是這樣的:如何在Entity Framework中使用相同的存儲過程插入,更新和刪除?
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
有什麼想法嗎?
您在使用我的Windows應用程序不asp.net嘗試新鮮事物 –