6.6 OracleDataAdapterクラス
OracleDataAdapter
オブジェクトは、DataSet
を移入し、DataSet
における変更をOracle Databaseに反映させるデータ・プロバイダ・オブジェクトを表します。
クラスの継承
System.Object
System.MarshalByRefObject
System.ComponentModel.Component
System.Data.Common.DataAdapter
System.Data.Common.DbDataAdapter
Oracle.DataAccess.Client.OracleDataAdapter
宣言
// C# public sealed class OracleDataAdapter : DbDataAdapter, IDbDataAdapter
要件
プロバイダ | ODP.NET管理対象外ドライバ | ODP.NET管理対象ドライバ |
---|---|---|
アセンブリ |
|
|
ネームスペース |
|
|
.NET Framework |
3.5, 4.5, 4.6 |
4.5, 4.6 |
スレッド安全性
パブリック静的メソッドはスレッドセーフですが、インスタンス・メソッドではスレッド安全性は保証されません。
例
次の例では、EMP
表の更新にOracleDataAdapter
およびデータセットが使用されています。
// C# using System; using System.Data; using Oracle.DataAccess.Client; class OracleDataAdapterSample { static void Main() { string constr = "User Id=scott;Password=tiger;Data Source=oracle"; string cmdstr = "SELECT empno, 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; // Now update the EMP using the adapter // The OracleCommandBuilder will create the UpdateCommand for the // adapter to update the EMP table adapter.Update(dataset, "EMP"); Console.WriteLine("Row updated successfully"); } }