このようにして、直接更新文を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();
}
EDIT:(?データテーブル、データセット)
あなたは、あなたが、元のデータソースを維持する必要が変更されている(および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ですが、この場合、最初の例に戻ってStoredProcedureを使用するようにOracleCommandを調整する必要があります(すべてのフィールドをパラメータとして追加し、CommandTypeをCommandTypeに変更します) StoredProcedureコマンドのテキストをStoredProcedureの名前に変更します)。次に、StoredProcedureは、更新が必要なフィールドを選択します。
あなたはEntity Frameworkを使用していますか? – sarwar026
いいえ私はODP.NET(Oracle.Access.Dll)を使用します –