【发布时间】:2009-05-14 02:20:11
【问题描述】:
数据库抛出异常导致FOREIGN KEY冲突。
【问题讨论】:
标签: asp.net data-binding objectdatasource
数据库抛出异常导致FOREIGN KEY冲突。
【问题讨论】:
标签: asp.net data-binding objectdatasource
查看 ObjectDataSource 上的 eventargs。应该有一个 e.Exception 和 e.Results,您可以查询更新的成功/错误。
protected void MyOds_Updated(object sender, ObjectDataSourceStatusEventArgs e)
{
if (e.Exception != null)
{
// handle exception here.
}
}
【讨论】:
要告诉 ObjectDataSource 不要重新抛出您的异常,您必须将 ExceptionHandled 标志设置为 True。
protected void MyOds_Updated(object sender, ObjectDataSourceStatusEventArgs e)
{
if (e.Exception != null)
{
//this tells the ObjectDatasource : It's ok, i'm taking care of this
//and don't rethrow it.
e.ExceptionHandled = true
// handle exception here (log/display to user etc ...)
}
}
希望对你有帮助。
咒语。
【讨论】:
如果这对使用网格视图更新方法没有帮助
If Not e.Exception Is Nothing Then
e.KeepInEditMode = True
e.ExceptionHandled = True
msg("error .", "a", Me.GetType(), ClientScript)
End If
【讨论】: