ADO.NET Provider for Paylocity

Build 23.0.8839

DataAdapter を使用したクエリ

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

PaylocityDataAdapter の使用

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

次の例は、Employee テーブルのFirstName カラムとLastName カラムを選択します。

C#

string connectionString = "InitiateOauth=GETANDREFRESH;OAuthClientID=YourClientId;OAuthClientSecret=YourClientSecret;CompanyId=YourCompanyId;";

using (PaylocityConnection connection = new PaylocityConnection(connectionString)) {
  PaylocityDataAdapter dataAdapter = new PaylocityDataAdapter(
  "SELECT FirstName, LastName FROM Employee", connection);

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

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

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

VB.NET

Dim connectionString As String = "InitiateOauth=GETANDREFRESH;OAuthClientID=YourClientId;OAuthClientSecret=YourClientSecret;CompanyId=YourCompanyId;"

Using connection As New PaylocityConnection(connectionString)
  Dim dataAdapter As New PaylocityDataAdapter("SELECT FirstName, LastName FROM Employee", connection)

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

  Console.WriteLine("Contents of Employee.")

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

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