SqlCeDataAdapter.RowUpdating イベント

Update の呼び出し中に、データ ソースに対して更新コマンドが実行される前に発生します。更新が試行されると、このイベントが発生します。

名前空間:  System.Data.SqlServerCe
アセンブリ:  System.Data.SqlServerCe (System.Data.SqlServerCe.dll)

構文

'宣言
Public Event RowUpdating As SqlCeRowUpdatingEventHandler
'使用
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 では、イベントは使用できますが、新規に宣言することはできません。

説明

Update を使用すると、データ行が更新されるたびに 2 つのイベントが発生します。次の順序で処理が実行されます。

  1. DataRow 内の値が、パラメーター値に移動されます。

  2. OnRowUpdating イベントが発生します。

  3. コマンドが実行されます。

  4. コマンドが FirstReturnedRecord に設定されている場合は、最初に返された結果が DataRow に格納されます。

  5. OnRowUpdated イベントが発生します。

  6. AcceptChanges が呼び出されます。

使用例

RowUpdating イベントと 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);
}

関連項目

参照

SqlCeDataAdapter クラス

System.Data.SqlServerCe 名前空間