ADO.NET Provider for MYOB

Build 24.0.8963

DataAdapter を使用したクエリ

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

MYOBDataAdapter の使用

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

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

C#

string connectionString = " If using an online instance: InitiateOAuth=GETANDREFRESH;OAuthClientId=YourClientId;OAuthClientSecret=YourClientSecret;CompanyFileId=yourCompanyFileId;CallbackURL=http://localhost:33333;User=companyFileUser;Password=companyFilePassword; If using an on premise instance: InitiateOAuth=OFF;URL=http://localhost:8080/accountright;CompanyFileId=327eed10-9615-4e5e-bd9e-ae2cc00e2c70;User=companyFileUser;Password=companyFilePassword;";

using (MYOBConnection connection = new MYOBConnection(connectionString)) {
  MYOBDataAdapter dataAdapter = new MYOBDataAdapter(
  "SELECT Id, Name FROM Accounts", connection);

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

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

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

VB.NET

Dim connectionString As String = " If using an online instance: InitiateOAuth=GETANDREFRESH;OAuthClientId=YourClientId;OAuthClientSecret=YourClientSecret;CompanyFileId=yourCompanyFileId;CallbackURL=http://localhost:33333;User=companyFileUser;Password=companyFilePassword; If using an on premise instance: InitiateOAuth=OFF;URL=http://localhost:8080/accountright;CompanyFileId=327eed10-9615-4e5e-bd9e-ae2cc00e2c70;User=companyFileUser;Password=companyFilePassword;"

Using connection As New MYOBConnection(connectionString)
  Dim dataAdapter As New MYOBDataAdapter("SELECT Id, Name FROM Accounts", connection)

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

  Console.WriteLine("Contents of Accounts.")

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

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