簡體   English   中英

如何捕獲異常形式ObjectDataSource.Updata()

[英]How can I catch a exception form ObjectDataSource.Updata()

由數據庫引發的異常導致FOREIGN KEY發生沖突。

查看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 ...)
    }
}

我希望這能幫到您。

Manitra。

如果這沒有幫助使用網格視圖更新方法

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM