この方法で、直接更新ステートメントを Oracle エンジンに送信できます。
using (OracleConnection cnn = new OracleConnection(connString))
using (OracleCommand cmd = new OracleCommand("UPDATE TABLE1 SET BIRHDATE=:NewDate WHERE ID=:ID", cnn))
{
cmd.Parameters.AddWithValue(":NewDate", YourDateTimeValue);
cmd.Parameters.AddWithValue(":ID", 111);
cnn.Open();
cmd.ExecuteNonQuery();
}
編集:
どのフィールドが変更されたかわからない (そして ORM ツールを使用したくない) 場合は、最初にフィールドに入力するために使用された元のデータソース (データテーブル、データセット?) を保持する必要があります。次に、関連する行を更新し、OracleDataAdapter を使用します。
using(OracleConnection cnn = new OracleConnection(connString))
using (OracleCommand cmd = new OracleCommand("SELECT * FROM TABLE1 WHERE 1=0", cnn))
{
OracleAdapter adp = new OracleDataAdapter();
adp.SelectCommand = cmd;
// The OracleDataAdapter will build the required string for the update command
// and will act on the rows inside the datatable who have the
// RowState = RowState.Changed Or Inserted Or Deleted
adp.Update(yourDataTable);
}
このアプローチは、データベースへの 2 回のトリップを必要とするため、非効率的であることに注意してください。最初にテーブル構造を発見し、2 番目に変更された行を更新します。さらに、OracleDataAdapter が必要な UpdateCommand/InsertCommand/DeleteCommand を準備するには、テーブルに主キーが必要です。
逆に、これは更新する行が多い場合に便利です。
最後の (そしておそらく最速の) 代替手段は StoredProcedure ですが、この場合、最初の例に戻って、OracleCommand を StoredProcedure を使用するように調整する必要があります (すべてのフィールドをパラメーターとして追加し、CommandType を CommandType.StoredProcedure に変更し、コマンドのテキストを StoredProcedure の名前にします)。次に、StoredProcedure は更新が必要なフィールドを選択します。