爲什麼這個SP返回TRUE,即使我提到如果某些條件滿足,那麼它應該提高錯誤,但它仍然返回true。我已經檢查了條件,它正在開會,但仍然如此,爲什麼?爲什麼我的存儲過程返回true,即使它引發錯誤?
SP:
ALTER PROC [dbo].[usp_UpdateWithdrawal]
(
@NITNo int,
@WorkNo int,
@ContractorID int,
@IsWithDrawn bit
)
AS
BEGIN
Begin Try
Begin Transaction
Declare @ExpiryDate date
Declare @ExpiryTime time(7)
Set @ExpiryDate= (Select convert(varchar(11), ExpiryDate, 106) from Works where NIT_No= @NITNo and WorkNo= @WorkNo)
Set @ExpiryTime= (Select CAST(ExpiryTime as TIME(0)) from Works where NIT_No= @NITNo and WorkNo= @WorkNo)
IF(CONVERT(varchar(11), @ExpiryDate, 106)+' '+Convert(varchar(8),CAST(@ExpiryTime as TIME(0))) < CONVERT(varchar(11), Getdate(), 106)+' '+Convert(varchar(8),CAST(Getdate() as TIME(0))))
Begin
RAISERROR('Sorry, Expiry Date and Time has passed', 16, 10);
return;
End
Update AppliedWorks
Set Withdrawn= @IsWithDrawn
Where NIT_No= @NITNo and Work_No= @WorkNo and Contractor_ID= @ContractorID and
CONVERT(varchar(11), @ExpiryDate, 106)+' '+Convert(varchar(8),CAST(@ExpiryTime as TIME(0))) < CONVERT(varchar(11), Getdate(), 106)+' '+Convert(varchar(8),CAST(Getdate() as TIME(0)))
--Update Hisotry
Declare @AppliedWorkID int
Set @AppliedWorkID= (Select AppliedWorkID from AppliedWorks
Where NIT_No= @NITNo and Work_No= @WorkNo and Contractor_ID= @ContractorID)
Insert into AppliedWorkHistory
(
AppliedWork_ID,
FinancialMoney,
AboveBelow,
EntryDateTime,
TwoPercentAmount,
TwoPercentBankName,
TwoPercentDemandDaftNo,
TwoPercentDemandDaftValue,
TwoPercentRemarks,
EightPercentAmount,
EightPercentBankName,
EightPercentDemandDaftNo,
EightPercentDemandDaftValue,
EightPercentRemarks,
IsFinalized,
Withdrawn
)
Select @AppliedWorkID, aw.FinancialMoney, aw.AboveBelow, Getdate(), aw.TwoPercentAmount, aw.TwoPercentBankName, aw.EightPercentDemandDaftNo,
aw.TwoPercentDemandDaftValue, aw.TwoPercentRemarks, aw.EightPercentAmount, aw.EightPercentBankName,
aw.EightPercentDemandDaftNo, aw.EightPercentDemandDaftValue, aw.EightPercentRemarks, aw.IsFinalized, @IsWithDrawn
from AppliedWorks aw where aw.AppliedWorkID= @AppliedWorkID
Commit Transaction
End Try
Begin Catch
Rollback transaction
End Catch
END;
C#:
公共靜態布爾UpdateWithdrawal(INT NitNo,INT WorkNo,INT ContractorID,布爾IsWithDrawn) { 布爾結果;
ClsDatabaseManager dbManager = ClsDatabaseManager.InitializeDbManager(Constants.Databases.TendersConnection);
try
{
dbManager.CreateParameters(4);
dbManager.AddParameters(0, "@NITNo", NitNo);
dbManager.AddParameters(1, "@WorkNo", WorkNo);
dbManager.AddParameters(2, "@ContractorID", ContractorID);
dbManager.AddParameters(3, "@IsWithDrawn", IsWithDrawn);
dbManager.Open();
Result = dbManager.ExecuteNonQuery("usp_UpdateWithdrawal", CommandType.StoredProcedure).ToBool();
}
catch (Exception ex)
{
throw ex;
}
finally
{
dbManager.Close();
dbManager.Dispose();
}
return Result;
}
您在'TRY..CATCH'中引發錯誤,並且沒有在'CATCH'中處理它,您需要將錯誤拋入您的'CATCH'部分以及 – Stephen
。在答案框中寫下你的留言,這樣我就可以標記它 – Covert