Share via


Evento SqlCeDataAdapter.RowUpdating

Aparece durante una llamada a Update antes de que se ejecute un comando de actualización en el origen de datos. Se hace un intento de actualización y, a continuación, se inicia el evento.

Espacio de nombres:  System.Data.SqlServerCe
Ensamblado:  System.Data.SqlServerCe (en System.Data.SqlServerCe.dll)

Sintaxis

'Declaración
Public Event RowUpdating As SqlCeRowUpdatingEventHandler
'Uso
Dim instance As SqlCeDataAdapter
Dim handler As SqlCeRowUpdatingEventHandler

AddHandler instance.RowUpdating, handler
public event SqlCeRowUpdatingEventHandler RowUpdating
public:
 event SqlCeRowUpdatingEventHandler^ RowUpdating {
    void add (SqlCeRowUpdatingEventHandler^ value);
    void remove (SqlCeRowUpdatingEventHandler^ value);
}
member RowUpdating : IEvent<SqlCeRowUpdatingEventHandler,
    SqlCeRowUpdatingEventArgs>
JScript admite el uso de eventos, pero no la declaración de otros nuevos.

Comentarios

Cuando se utiliza Update hay dos eventos que se producen por cada fila de datos actualizada. El orden de ejecución es el siguiente:

  1. Los valores de DataRow se trasladan a los valores de parámetros.

  2. Se provoca el evento OnRowUpdating.

  3. Se ejecuta el comando.

  4. Si el comando se establece en FirstReturnedRecord, el primer resultado devuelto se coloca en DataRow.

  5. Se provoca el evento OnRowUpdated.

  6. Se llama al método AcceptChanges.

Ejemplos

El ejemplo siguiente muestra los eventos RowUpdating y RowUpdated en uso.

Public Sub Snippet5()
    ' Create DataAdapter
    '
    Dim adp As New SqlCeDataAdapter("SELECT * FROM products", "Data Source = MyDatabase.sdf")

    Dim cb As New SqlCeCommandBuilder(adp)

    ' Create and fill the dataset (select only first 5 rows)
    '
    Dim ds As New DataSet()
    adp.Fill(ds, 0, 5, "Table")

    ' Modify dataSet
    '
    Dim table As DataTable = ds.Tables("Table")
    table.Rows(1)("Product Name") = "Asian Chai"

    ' Add handlers
    '
    AddHandler adp.RowUpdating, AddressOf OnRowUpdating
    AddHandler adp.RowUpdated, AddressOf OnRowUpdated

    ' Update, this operation fires two events (RowUpdating/RowUpdated)  
    '
    adp.Update(ds, "Table")

    ' Remove handlers
    '
    RemoveHandler adp.RowUpdating, AddressOf OnRowUpdating
    RemoveHandler adp.RowUpdated, AddressOf OnRowUpdated

End Sub 'Snippet5


Private Shared Sub OnRowUpdating(ByVal sender As Object, ByVal e As SqlCeRowUpdatingEventArgs)
    Console.WriteLine("OnRowUpdating")
    Console.WriteLine(e.Command.CommandText)
    Console.WriteLine(e.StatementType)
    Console.WriteLine(e.Status)

End Sub 'OnRowUpdating


Private Shared Sub OnRowUpdated(ByVal sender As Object, ByVal e As SqlCeRowUpdatedEventArgs)
    Console.WriteLine("OnRowUpdated")
    Console.WriteLine(e.Command.CommandText)
    Console.WriteLine(e.StatementType)
    Console.WriteLine(e.Status)

End Sub 'OnRowUpdated
public void Snippet5()
{
    // Create DataAdapter
    //
    SqlCeDataAdapter adp = new SqlCeDataAdapter(
        "SELECT * FROM products",
        "Data Source = MyDatabase.sdf");

    SqlCeCommandBuilder cb = new SqlCeCommandBuilder(adp);

    // Create and fill the dataset (select only first 5 rows)
    //
    DataSet ds = new DataSet();
    adp.Fill(ds, 0, 5, "Table");

    // Modify dataSet
    //
    DataTable table = ds.Tables["Table"];
    table.Rows[1]["Product Name"] = "Asian Chai";

    // Add handlers
    //
    adp.RowUpdating += new SqlCeRowUpdatingEventHandler(OnRowUpdating);
    adp.RowUpdated += new SqlCeRowUpdatedEventHandler(OnRowUpdated);

    // Update, this operation fires two events (RowUpdating/RowUpdated)  
    //
    adp.Update(ds, "Table");

    // Remove handlers
    //
    adp.RowUpdating -= new SqlCeRowUpdatingEventHandler(OnRowUpdating);
    adp.RowUpdated -= new SqlCeRowUpdatedEventHandler(OnRowUpdated);
}

private static void OnRowUpdating(object sender, SqlCeRowUpdatingEventArgs e)
{
    Console.WriteLine("OnRowUpdating");
    Console.WriteLine(e.Command.CommandText);
    Console.WriteLine(e.StatementType);
    Console.WriteLine(e.Status);
}

private static void OnRowUpdated(object sender, SqlCeRowUpdatedEventArgs e)
{
    Console.WriteLine("OnRowUpdated");
    Console.WriteLine(e.Command.CommandText);
    Console.WriteLine(e.StatementType);
    Console.WriteLine(e.Status);
}

Vea también

Referencia

SqlCeDataAdapter Clase

Espacio de nombres System.Data.SqlServerCe