LinqDataSourceStatusEventArgs.Exception Özellik

Tanım

Veri işlemi sırasında oluşturulan özel durumu alır.

public:
 property Exception ^ Exception { Exception ^ get(); };
public Exception Exception { get; }
member this.Exception : Exception
Public ReadOnly Property Exception As Exception

Özellik Değeri

Hata Exception oluştuysa özel durumu temsil eden bir nesne; aksi takdirde, null.

Örnekler

Aşağıdaki örnekte olay için bir olay işleyicisi gösterilmektedir Inserted . Olay işleyicisinde özelliği ise Exceptionnull, ürün kimliği özelliğindeki Result nesnesinden alınır. Ürün kimliği, tablo için birincil anahtardır ve veritabanı tarafından ayarlanır, bu nedenle ekleme işlemi tamamlanana kadar değer bilinmez. Özelliği ile eşit değilse Exception özel durum iletisi günlüğe nullkaydedilir. Özelliği ExceptionHandled daha sonra olarak trueayarlanır.

protected void LinqDataSource_Inserted(object sender, LinqDataSourceStatusEventArgs e)
{
    if (e.Exception == null)
    {
        Product newProduct = (Product)e.Result;
        Literal1.Text = "The new product id is " + newProduct.ProductID;
        Literal1.Visible = true;            
    }
    else
    {
        LogError(e.Exception.Message);
        Literal1.Text = "We are sorry. There was a problem saving the record. The administrator has been notified.";
        Literal1.Visible = true;
        e.ExceptionHandled = true;            
    }
}
Protected Sub LinqDataSource_Inserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LinqDataSourceStatusEventArgs)
    If (IsNothing(e.Exception)) Then
        Dim newProduct As Product
        newProduct = CType(e.Result, Product)
        Literal1.Text = "The new product id is " & newProduct.ProductID
        Literal1.Visible = True
    Else
        LogError(e.Exception.Message)
        Literal1.Text = "We are sorry. There was a problem saving the record. The administrator has been notified."
        Literal1.Visible = True
        e.ExceptionHandled = True
    End If
End Sub

Açıklamalar

Veri işlemi sırasında bir özel durum oluşursa, özel durum özelliğinde Exception depolanır. , , Deleted, InsertedSelectedve olayları için ContextCreatedolay işleyicileri oluşturabilir ve Updated varsa özel durumu özelliği aracılığıyla Exception alabilirsiniz.

Şunlara uygulanır