gpt4 book ai didi

asp.net - 在ASP.net中显示SQL错误

转载 作者:行者123 更新时间:2023-12-03 07:54:10 24 4
gpt4 key购买 nike

我有以下存储过程。但是我不知道如何从SQL Server抛出错误并在JavaScript Alert上显示它。

这是存储过程

Begin
if EXISTS(select * from POS_Transactions where ID = @transId)
Begin
declare @totalAmount money

select @totalAmount = TotalAmount
from POS_Transactions
where ID = @transId and PAN = @pan

update pos_transactions
set transactiontypeid = 3
where id = @transId

update cardbalance
set cardbalance = (cardbalance + @totalAmount),
totalredemption = (totalredemption - @totalAmount)
where pan = @pan
END
Else
--Show Error Here
BEGIN
END

这是VB代码:
Try
If txtEmbossLine.Text <> "" And txtTransactionId.Text <> "" Then
Utilities.VoidRedemption(txtEmbossLine.Text, txtTransactionId.Text)
Response.Write("<script>alert('Redemption Voided successfully')</script>")
Else
Response.Write("<script>alert('Please enter both fields')</script>")
End If
Catch ex As Exception
Response.Write(ex.Message)
End Try

最佳答案

您可以使用以下代码 throw SQL Server的异常:

throw 50001, 'Some error', 1

C#代码中的 try ... catch将为您完成其余工作。

关于asp.net - 在ASP.net中显示SQL错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31561248/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com