ADO.NET Provider for Xero

Build 22.0.8479

DataAdapter を使用したクエリ

CData ADO.NET Provider for Xero では、次の2つのネイティブ.NET インターフェースを使用して、Xero からデータを取得できます。XeroDataAdapter オブジェクトおよびXeroDataReader オブジェクト。各オブジェクトは同じタスク(データの取得)を実行しますが、実行方法が異なります。XeroDataAdapter オブジェクトはクエリに一致するすべてのデータを取得しますが、XeroDataReader オブジェクトは必要に応じてインクリメントしながら一部のデータだけをフェッチします。

XeroDataAdapter の使用

アダプターのFill メソッドを使用して、データソースからデータを取得します。空のDataTable インスタンスがFill メソッドへの引数として渡されます。このメソッドが戻ってきたとき、DataTable インスタンスにはクエリされたデータが設定されています。Fill メソッドは、戻る前にデータソースからすべてのデータを取得する必要があるため、XeroDataAdapter はXeroDataReader よりも時間がかかります。

次の例は、Contacts テーブルのDiscount カラムとName カラムを選択します。

C#

string connectionString = "InitiateOAuth=GETANDREFRESH;";

using (XeroConnection connection = new XeroConnection(connectionString)) {
  XeroDataAdapter dataAdapter = new XeroDataAdapter(
  "SELECT Discount, Name FROM Contacts", connection);

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

  Console.WriteLine("Contents of Contacts.");

  foreach (DataRow row in table.Rows) {
    Console.WriteLine("{0}: {1}", row["Discount"], row["Name"]);
  }
}

VB.NET

Dim connectionString As String = "InitiateOAuth=GETANDREFRESH;"

Using connection As New XeroConnection(connectionString)
  Dim dataAdapter As New XeroDataAdapter("SELECT Discount, Name FROM Contacts", connection)

  Dim table As New DataTable()
  dataAdapter.Fill(table)

  Console.WriteLine("Contents of Contacts.")

  For Each row As DataRow In table.Rows
    Console.WriteLine("{0}: {1}", row("Discount"), row("Name"))
  Next
End Using

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