LinqDataSource.Inserted Événement

Définition

Se produit une fois l'opération d'insertion terminée.

public:
 event EventHandler<System::Web::UI::WebControls::LinqDataSourceStatusEventArgs ^> ^ Inserted;
public event EventHandler<System.Web.UI.WebControls.LinqDataSourceStatusEventArgs> Inserted;
member this.Inserted : EventHandler<System.Web.UI.WebControls.LinqDataSourceStatusEventArgs> 
Public Custom Event Inserted As EventHandler(Of LinqDataSourceStatusEventArgs) 

Type d'événement

Exemples

L’exemple suivant montre comment créer un gestionnaire d’événements pour l’événement Inserted qui recherche les exceptions et récupère la propriété identity pour le nouvel enregistrement.

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

Remarques

Gérez l’événement Inserted pour intercepter les exceptions de l’opération d’insertion ou pour examiner les valeurs une fois l’opération d’insertion terminée. Vous pouvez récupérer les nouvelles valeurs via l’objet LinqDataSourceStatusEventArgs passé aux gestionnaires d’événements. Par exemple, vous pouvez utiliser l’objet LinqDataSourceStatusEventArgs pour récupérer la propriété d’identité générée par une base de données pour un nouvel enregistrement de données.

S’applique à