ADO.NET Provider for Square

Build 23.0.8839

DataAdapter を使用したクエリ

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

SquareDataAdapter の使用

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

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

C#

string connectionString = "InitiateOAuth=GETANDREFRESH;OAuthClientId=MyApplicationId;OAuthClientSecret=MyApplicationSecret;CallbackURL=http://localhost:33333;LocationId=MyDefaultLocation";

using (SquareConnection connection = new SquareConnection(connectionString)) {
  SquareDataAdapter dataAdapter = new SquareDataAdapter(
  "SELECT Id, DeviceName FROM Payments", connection);

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

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

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

VB.NET

Dim connectionString As String = "InitiateOAuth=GETANDREFRESH;OAuthClientId=MyApplicationId;OAuthClientSecret=MyApplicationSecret;CallbackURL=http://localhost:33333;LocationId=MyDefaultLocation"

Using connection As New SquareConnection(connectionString)
  Dim dataAdapter As New SquareDataAdapter("SELECT Id, DeviceName FROM Payments", connection)

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

  Console.WriteLine("Contents of Payments.")

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

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