ADO.NET Provider for Sage Business Cloud Accounting

Build 22.0.8479

データの変更

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

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

C#

using (SageBCAccountingConnection connection = new SageBCAccountingConnection(connectionString)) {
  SageBCAccountingDataAdapter dataAdapter = new SageBCAccountingDataAdapter(
    "SELECT Id, Column1 FROM SampleTable_1", connection);

  dataAdapter.UpdateCommand = new SageBCAccountingCommand(
    "UPDATE SampleTable_1 SET Column1 = @Column1 " +
    "WHERE Id = @Id", connection);
 
  dataAdapter.UpdateCommand.Parameters.Add(new SageBCAccountingParameter("@Column1", DbType.String, "Column1"));
  dataAdapter.UpdateCommand.Parameters.Add(new SageBCAccountingParameter("@Id", DbType.String, "Id"));
  dataAdapter.UpdateCommand.Parameters[1].SourceVersion = DataRowVersion.Original;

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

  DataRow firstrow = table.Rows[0];
  firstrow["Column1"] = "Jon Doe";

  dataAdapter.Update(table);

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

VB.NET

Using connection As New SageBCAccountingConnection(connectionString)
  Dim dataAdapter As New SageBCAccountingDataAdapter(
    "SELECT Id, Column1 FROM SampleTable_1", connection)
  
  dataAdapter.UpdateCommand = New SageBCAccountingCommand(
    "UPDATE SampleTable_1 SET Column1 = @Column1 " +
    "WHERE Id = @Id", connection)
  
  dataAdapter.UpdateCommand.Parameters.Add(new SageBCAccountingParameter("@Column1", DbType.String, "Column1"))
  dataAdapter.UpdateCommand.Parameters.Add(new SageBCAccountingParameter("@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("Column1") = "Jon Doe"
  
  dataAdapter.Update(table)
  
  Console.WriteLine("Rows after update.")
  
  For Each row As DataRow In table.Rows
    Console.WriteLine("{0}: {1}", row("Id"), row("Column1"))
  Next
End Using

Copyright (c) 2023 CData Software, Inc. - All rights reserved.
Build 22.0.8479