【问题标题】:How can I catch a exception form ObjectDataSource.Updata()如何捕获异常表单 ObjectDataSource.Updata()
【发布时间】:2009-05-14 02:20:11
【问题描述】:

数据库抛出异常导致FOREIGN KEY冲突。

【问题讨论】:

    标签: asp.net data-binding objectdatasource


    【解决方案1】:

    查看 ObjectDataSource 上的 eventargs。应该有一个 e.Exception 和 e.Results,您可以查询更新的成功/错误。

    protected void MyOds_Updated(object sender, ObjectDataSourceStatusEventArgs e)
    {
        if (e.Exception != null)
        {
            // handle exception here.
        }
    }
    

    【讨论】:

    • 非常感谢。但我发现我的问题仍然存在。当更新方法没有响应时,更新事件发生异常。我必须覆盖 ObjectDataSource.Update() 或 ObjectDataSourceView 吗?
    【解决方案2】:

    要告诉 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 ...)
        }
    }
    

    希望对你有帮助。

    咒语。

    【讨论】:

      【解决方案3】:

      如果这对使用网格视图更新方法没有帮助

      If Not e.Exception Is Nothing Then
          e.KeepInEditMode = True
          e.ExceptionHandled = True
          msg("error .", "a", Me.GetType(), ClientScript)
      End If
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-10-06
        • 1970-01-01
        • 2017-03-14
        • 2016-12-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多