6.6.6.1 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
からの継承)Command
のUpdateStatus
-
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"); } }