データの変更
アダプターのUpdate メソッドを使用して、データを更新します。このオーバーロードされたメソッドは、パラメータとしてDataTable を受け取ることができ、データソースに対して行われたすべての変更をコミットします。 データテーブルの名前は、引数として渡すことができ、従来の方法でデータセット全体を更新するためにも使用されます。 データテーブルをUpdate メソッドへの引数として使用する場合、アダプターは、データテーブルに対して行われた変更を評価し、行ごとに適切なコマンド(INSERT、UPDATE、またはDELETE)を実行します。
次の例は、Projects エントリの1つであるName を更新します。
C#
using (JIRAConnection connection = new JIRAConnection(connectionString)) { JIRADataAdapter dataAdapter = new JIRADataAdapter( "SELECT Key, Name FROM Projects", connection); dataAdapter.UpdateCommand = new JIRACommand( "UPDATE Projects SET Name = @Name " + "WHERE Id = @Id", connection); dataAdapter.UpdateCommand.Parameters.Add(new JIRAParameter("@Name", DbType.String, "Name")); dataAdapter.UpdateCommand.Parameters.Add(new JIRAParameter("@Id", DbType.String, "Id")); dataAdapter.UpdateCommand.Parameters[1].SourceVersion = DataRowVersion.Original; DataTable table = new DataTable(); dataAdapter.Fill(table); DataRow firstrow = table.Rows[0]; firstrow["Name"] = "Test Project."; dataAdapter.Update(table); Console.WriteLine("Rows after update."); foreach (DataRow row in table.Rows) { Console.WriteLine("{0}: {1}", row["Key"], row["Name"]); } }
VB.NET
Using connection As New JIRAConnection(connectionString) Dim dataAdapter As New JIRADataAdapter( "SELECT Key, Name FROM Projects", connection) dataAdapter.UpdateCommand = New JIRACommand( "UPDATE Projects SET Name = @Name " + "WHERE Id = @Id", connection) dataAdapter.UpdateCommand.Parameters.Add(new JIRAParameter("@Name", DbType.String, "Name")) dataAdapter.UpdateCommand.Parameters.Add(new JIRAParameter("@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("Name") = "Test Project." dataAdapter.Update(table) Console.WriteLine("Rows after update.") For Each row As DataRow In table.Rows Console.WriteLine("{0}: {1}", row("Key"), row("Name")) Next End Using