Share via


LinqDataSource.Inserted Kejadian

Definisi

Terjadi ketika operasi penyisipan telah selesai.

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) 

Jenis Acara

Contoh

Contoh berikut menunjukkan cara membuat penanganan aktivitas untuk Inserted peristiwa yang memeriksa pengecualian dan mengambil properti identitas untuk rekaman baru.

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

Keterangan

Inserted Tangani peristiwa untuk menangkap pengecualian apa pun dari operasi penyisipan atau untuk memeriksa nilai setelah operasi penyisipan selesai. Anda dapat mengambil nilai baru melalui LinqDataSourceStatusEventArgs objek yang diteruskan ke penanganan aktivitas. Misalnya, Anda dapat menggunakan LinqDataSourceStatusEventArgs objek untuk mengambil properti identitas yang dihasilkan oleh database untuk rekaman data baru.

Berlaku untuk