LinqDataSource.Inserted Evento

Definición

Tiene lugar cuando se termina una operación de inserción.

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) 

Tipo de evento

Ejemplos

En el ejemplo siguiente se muestra cómo crear un controlador de eventos para el Inserted evento que comprueba las excepciones y recupera la propiedad identity del nuevo registro.

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

Comentarios

Controle el Inserted evento para detectar las excepciones de la operación de inserción o para examinar los valores una vez finalizada la operación de inserción. Puede recuperar los nuevos valores a través del LinqDataSourceStatusEventArgs objeto que se pasa a los controladores de eventos. Por ejemplo, puede usar el LinqDataSourceStatusEventArgs objeto para recuperar la propiedad de identidad generada por una base de datos para un nuevo registro de datos.

Se aplica a