LinqDataSourceStatusEventArgs.Exception Eigenschap

Definitie

Hiermee wordt de uitzondering opgehaald die is opgetreden tijdens de gegevensbewerking.

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

Waarde van eigenschap

Een Exception object dat de uitzondering vertegenwoordigt, als er een fout is opgetreden; anders. null

Voorbeelden

In het volgende voorbeeld ziet u een gebeurtenis-handler voor de Inserted gebeurtenis. In de gebeurtenis-handler, als de Exception eigenschap is null, wordt de product-id opgehaald uit het object in de Result eigenschap. De product-id is een primaire sleutel voor de tabel en wordt ingesteld door de database, dus de waarde is pas bekend als de invoegbewerking is voltooid. Het uitzonderingsbericht wordt geregistreerd als de Exception eigenschap niet gelijk is aan null. De ExceptionHandled eigenschap wordt vervolgens ingesteld op true.

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

Opmerkingen

Als er een uitzondering optreedt tijdens de gegevensbewerking, wordt de uitzondering opgeslagen in de Exception eigenschap. U kunt gebeurtenis-handlers maken voor de ContextCreated, , en DeletedInsertedgebeurtenissen en Selected de uitzondering, indien van toepassing, ophalen via de UpdatedExceptioneigenschap.

Van toepassing op