プライマリ・コンテンツに移動
Oracle® Data Provider for .NET開発者ガイド
ODAC 12.2c リリース1 (12.2.0.1) for Microsoft Windows
E88311-03
目次へ移動
目次
索引へ移動
索引

前
次

RowUpdated

このイベントは、Update()メソッドで行が更新された場合に発生します。

宣言

// C#
public event OracleRowUpdatedEventHandler RowUpdated;

イベント・データ

イベント・ハンドラはOracleRowUpdatedEventArgsオブジェクトを受信し、イベントに関する情報を含む次のプロパティが、オブジェクトにより公開されます。

  • Command

    Update中に実行されたOracleCommand

  • Errors(RowUpdatedEventArgsからの継承)

    例外がある場合は、Update中に生成

  • RecordsAffected(RowUpdatedEventArgsからの継承)

    Commandの実行によって変更、挿入または削除された行数

  • Row(RowUpdatedEventArgsからの継承)

    Updateに対して送信されるDataRow

  • StatementType(RowUpdatedEventArgsからの継承)

    実行されたSQL文のタイプ

  • Status(RowUpdatedEventArgsからの継承)

    CommandUpdateStatus

  • TableMapping(RowUpdatedEventArgsからの継承)

    Update中に使用されたDataTableMapping

次の例では、RowUpdatingイベントおよびRowUpdatedイベントの使用方法を示します。

// C#
 
using System;
using System.Data;
using Oracle.DataAccess.Client;
 
class RowUpdatedSample
{
  // Event handler for RowUpdating event
  protected static void OnRowUpdating(object sender, 
                                      OracleRowUpdatingEventArgs e)
  {
    Console.WriteLine("Row updating.....");
    Console.WriteLine("Event arguments:");
    Console.WriteLine("Command Text: " + e.Command.CommandText);
    Console.WriteLine("Command Type: " + e.StatementType);
    Console.WriteLine("Status: " + e.Status);
  }
 
  // Event handler for RowUpdated event
  protected static void OnRowUpdated(object sender, 
                                     OracleRowUpdatedEventArgs e)
  {
    Console.WriteLine("Row updated.....");
    Console.WriteLine("Event arguments:");
    Console.WriteLine("Command Text: " + e.Command.CommandText);
    Console.WriteLine("Command Type: " + e.StatementType);
    Console.WriteLine("Status: " + e.Status);
  }
 
  static void Main()
  {
    string constr = "User Id=scott;Password=tiger;Data Source=oracle";
    string cmdstr = "SELECT EMPNO, ENAME, SAL FROM EMP";
 
    // Create the adapter with the selectCommand txt and the
    // connection string
    OracleDataAdapter adapter = new OracleDataAdapter(cmdstr, constr);
 
    // Create the builder for the adapter to automatically generate
    // the Command when needed
    OracleCommandBuilder builder = new OracleCommandBuilder(adapter);
 
    // Create and fill the DataSet using the EMP
    DataSet dataset = new DataSet();
    adapter.Fill(dataset, "EMP");
 
    // Get the EMP table from the dataset
    DataTable table = dataset.Tables["EMP"];
 
    // Indicate DataColumn EMPNO is unique
    // This is required by the OracleCommandBuilder to update the EMP table
    table.Columns["EMPNO"].Unique = true;
 
    // Get the first row from the EMP table
    DataRow row = table.Rows[0];
 
    // Update the salary
    double sal = double.Parse(row["SAL"].ToString());
    row["SAL"] = sal + .01;
 
    // Set the event handlers for the RowUpdated and the RowUpdating event
    // the OnRowUpdating() method will be triggered before the update, and
    // the OnRowUpdated() method will be triggered after the update
    adapter.RowUpdating += new OracleRowUpdatingEventHandler(OnRowUpdating);
    adapter.RowUpdated += new OracleRowUpdatedEventHandler(OnRowUpdated);
 
    // Now update the EMP using the adapter
    // The OracleCommandBuilder will create the UpdateCommand for the
    // adapter to update the EMP table
    // The OnRowUpdating() and the OnRowUpdated() methods will be triggered
    adapter.Update(dataset, "EMP");
  }
}