ADO.NET Provider for Microsoft Office 365

Build 23.0.8839

データの変更

アダプターのUpdate メソッドを使用して、データを更新します。このオーバーロードされたメソッドは、パラメータとしてDataTable を受け取ることができ、データソースに対して行われたすべての変更をコミットします。 データテーブルの名前は、引数として渡すことができ、従来の方法でデータセット全体を更新するためにも使用されます。 データテーブルをUpdate メソッドへの引数として使用する場合、アダプターは、データテーブルに対して行われた変更を評価し、行ごとに適切なコマンド(INSERT、UPDATE、またはDELETE)を実行します。

次の例は、Events エントリの1つであるlocation_displayName を更新します。

C#

using (Office365Connection connection = new Office365Connection(connectionString)) {
  Office365DataAdapter dataAdapter = new Office365DataAdapter(
    "SELECT Id, location_displayName FROM Events", connection);

  dataAdapter.UpdateCommand = new Office365Command(
    "UPDATE Events SET location_displayName = @location_displayName " +
    "WHERE Id = @Id", connection);
 
  dataAdapter.UpdateCommand.Parameters.Add(new Office365Parameter("@location_displayName", "location_displayName", DbType.String ));
  dataAdapter.UpdateCommand.Parameters.Add(new Office365Parameter("@Id", "Id", DbType.String ));
  dataAdapter.UpdateCommand.Parameters[1].SourceVersion = DataRowVersion.Original;

  DataTable table = new DataTable();
  dataAdapter.Fill(table);

  DataRow firstrow = table.Rows[0];
  firstrow["location_displayName"] = "Town Hall Grille";

  dataAdapter.Update(table);

  Console.WriteLine("Rows after update.");
  
  foreach (DataRow row in table.Rows) {
    Console.WriteLine("{0}: {1}", row["Id"], row["location_displayName"]);
  }
}

VB.NET

Using connection As New Office365Connection(connectionString)
  Dim dataAdapter As New Office365DataAdapter(
    "SELECT Id, location_displayName FROM Events", connection)
  
  dataAdapter.UpdateCommand = New Office365Command(
    "UPDATE Events SET location_displayName = @location_displayName " +
    "WHERE Id = @Id", connection)
  
  dataAdapter.UpdateCommand.Parameters.Add(new Office365Parameter("@location_displayName", "location_displayName" DbType.String ))
  dataAdapter.UpdateCommand.Parameters.Add(new Office365Parameter("@Id", "Id", DbType.String))
  dataAdapter.UpdateCommand.Parameters(1).SourceVersion = DataRowVersion.Original
  
  Dim table As New DataTable()
  dataAdapter.Fill(table)
  
  Dim firstrow As DataRow = table.Rows(0)
  firstrow("location_displayName") = "Town Hall Grille"
  
  dataAdapter.Update(table)
  
  Console.WriteLine("Rows after update.")
  
  For Each row As DataRow In table.Rows
    Console.WriteLine("{0}: {1}", row("Id"), row("location_displayName"))
  Next
End Using

CData メソッドの拡張

INSERT を実行した後に複合主キーを取得する場合、どのようなタイプのINSERT が実行されたかによって最適なメソッドが異なります。

INSERT が単一の更新 / 削除ステートメントであった場合は、connection.GetLastResult() メソッドを使用して、挿入されたID を取得します。

INSERT がバッチ操作で、1行のみ更新された場合は、connection.GetLastResult() を使用して挿入されたID を取得します。これは、単一の更新 / 削除からID を取得するのと同じです。

INSERT がバッチ操作で、複数行が更新された場合は、直接SYS_LASTRESULTINFO にクエリを実行してLASTRESULTINTO#TEMP テーブルから挿入されたID を取得します。

Copyright (c) 2024 CData Software, Inc. - All rights reserved.
Build 23.0.8839