SqlCeDataAdapter.RowUpdating Event

Se produit lors d'un appel à Update avant l'exécution d'une commande de mise à jour sur la source de données. La tentative de mise à jour provoque le déclenchement de l'événement.

Espace de noms: System.Data.SqlServerCe
Assembly: System.Data.SqlServerCe (dans system.data.sqlserverce.dll)

Syntaxe

'Déclaration
Public Event RowUpdating As SqlCeRowUpdatingEventHandler
public event SqlCeRowUpdatingEventHandler RowUpdating
public:
event SqlCeRowUpdatingEventHandler^ RowUpdating {
    void add (SqlCeRowUpdatingEventHandler^ value);
    void remove (SqlCeRowUpdatingEventHandler^ value);
}
/** @event */
public void add_RowUpdating (SqlCeRowUpdatingEventHandler value)

/** @event */
public void remove_RowUpdating (SqlCeRowUpdatingEventHandler value)
JScript prend en charge l'utilisation d'événements, mais pas la déclaration de nouveaux événements.

Exemple

L'exemple suivant illustre l'utilisation des événements RowUpdating et RowUpdated.

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);
}

Remarques

Lors de l'utilisation de Update, deux événements se produisent pour chaque ligne de données mise à jour. L'ordre d'exécution est le suivant :

  1. Les valeurs contenues dans DataRow sont déplacées vers les valeurs du paramètre.

  2. L'événement OnRowUpdating est déclenché.

  3. La commande s'exécute.

  4. Si la commande a la valeur FirstReturnedRecord, le premier résultat retourné est placé dans DataRow.

  5. L'événement OnRowUpdated est déclenché.

  6. La méthode AcceptChanges est appelée.

Plateformes

Plateformes de développement

Windows Vista, Windows Mobile 5.0, Windows XP Professional with Service Pack 2 (SP2), Windows Server 2003, Windows Mobile 2003 for Pocket PC, Windows CE 5.0
Informations sur la version
.NET Framework et NET Compact Framework
Pris en charge dans 3.5
.NET Framework
Pris en charge dans 3.0
.NET Compact Framework et .Net Framework
Pris en charge dans 2.0

Voir aussi

Référence

SqlCeDataAdapter Class
SqlCeDataAdapter Members
System.Data.SqlServerCe Namespace