jqgrid 错误状态:“错误”。错误代码:500 添加更有意义的消息
我有一个 jqgrid 工作正常。但是我的数据库有一个限制,我需要在添加时提供更有意义的验证方法。
问题是当我提交对话框时显示错误:错误状态:“错误”。错误代码:500
我更希望它显示由保存时引发的异常引起的实际错误:
违反唯一键约束“UKC_InvoiceId_ActivityId”。无法在对象“dbo.InvoiceLine”中插入重复的键。重复的键值为 (11, 1)。该声明已终止。
谁能告诉我如何实现这一目标?
I have a jqgrid which works fine. However there is a constraint in my database and I need to provide more meaningful validation method when adding.
The problem is when I submit the dialog shows the error: error Status: 'error'. Error code: 500
I would much prefer it to show the actual error caused by the exception thrown on save:
Violation of UNIQUE KEY constraint 'UKC_InvoiceId_ActivityId'. Cannot insert duplicate key in object 'dbo.InvoiceLine'. The duplicate key value is (11, 1). The statement has been terminated.
Can anybody tell me how to achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用 ASP.NET,则可以在实现行插入的代码上使用
try {...} catch (SqlException ex) {...}
块。您可以分析SqlException
内部的ex.Procedure、ex.Server、ex.LineNumber、ex.Message
值,并生成(抛出)另一个具有更易读消息的异常。您可以在错误消息中使用用户键入的文本,并解释用户必须修改哪些数据才能解决问题。If you use ASP.NET then you can use
try {...} catch (SqlException ex) {...}
block over the code which implement the row insertion. You can analyseex.Procedure, ex.Server, ex.LineNumber, ex.Message
values inside of theSqlException
and generate (throw) another exception with more readable message. You can use in the error message the texts typed by the user and explain which data the user have to modify to solve the problem.