クライアントインターフェイスガイド > TDV用TIBCO ADO .NET 2020データプロバイダー > ADO.NETの使用 > データの更新
 
データの更新
アダプタのUpdateメソッドを使用して、データを更新します。このオーバーロードされたメソッドは、DataTableをパラメーターとして受け取ることができ、データソースに加えられたすべての変更をコミットします。データテーブルの名前は引数として渡すことができ、従来の方法でデータセット全体を更新するために使用することもできます。 Updateメソッドの引数としてデータテーブルを使用する場合、アダプタはデータテーブルに加えられた変更を評価し、各行に対して適切なコマンド(INSERT、UPDATE、またはDELETE)を実行します。
 
次の例では、Productsエントリの1つのProductNameを更新します。
 
C#
 
using (CompositeConnection connection = new CompositeConnection(connectionString)) {
CompositeDataAdapter dataAdapter = new CompositeDataAdapter(
"SELECT Id, ProductName FROM Products", connection);
dataAdapter.UpdateCommand = new CompositeCommand(
"UPDATE Products SET ProductName = @ProductName " +
"WHERE Id = @Id", connection);
dataAdapter.UpdateCommand.Parameters.Add(new CompositeParameter("@ProductName", DbType.String, "ProductName"));
dataAdapter.UpdateCommand.Parameters.Add(new CompositeParameter("@Id", DbType.String, "Id"));
dataAdapter.UpdateCommand.Parameters[1].SourceVersion = DataRowVersion.Original;
DataTable table = new DataTable();
dataAdapter.Fill(table);
DataRow firstrow = table.Rows[0];
firstrow["ProductName"] = "Ikura";
dataAdapter.Update(table);
Console.WriteLine("Rows after update.");
foreach (DataRow row in table.Rows) {
Console.WriteLine("{0}: {1}", row["Id"], row["ProductName"]);
}
}
 
VB.NET
 
Using connection As New CompositeConnection(connectionString)
Dim dataAdapter As New CompositeDataAdapter(
"SELECT Id, ProductName FROM Products", connection)
dataAdapter.UpdateCommand = New CompositeCommand(
"UPDATE Products SET ProductName = @ProductName " +
"WHERE Id = @Id", connection)
dataAdapter.UpdateCommand.Parameters.Add(new CompositeParameter("@ProductName", DbType.String, "ProductName"))
dataAdapter.UpdateCommand.Parameters.Add(new CompositeParameter("@Id", DbType.String, "Id"))
dataAdapter.UpdateCommand.Parameters(1).SourceVersion = DataRowVersion.Original
Dim table As New DataTable()
dataAdapter.Fill(table)
Dim firstrow As DataRow = table.Rows(0)
firstrow("ProductName") = "Ikura"
dataAdapter.Update(table)
Console.WriteLine("Rows after update.")
For Each row As DataRow In table.Rows
Console.WriteLine("{0}: {1}", row("Id"), row("ProductName"))
Next
End Using