DataAdapter を使用したクエリ
CData ADO.NET Provider for FreshBooks では、次の2つのネイティブ.NET インターフェースを使用して、FreshBooks からデータを取得できます。FreshBooksDataAdapter オブジェクトおよびFreshBooksDataReader オブジェクト。各オブジェクトは同じタスク(データの取得)を実行しますが、実行方法が異なります。FreshBooksDataAdapter オブジェクトはクエリに一致するすべてのデータを取得しますが、FreshBooksDataReader オブジェクトは必要に応じてインクリメントしながら一部のデータだけをフェッチします。
FreshBooksDataAdapter の使用
アダプターのFill メソッドを使用して、データソースからデータを取得します。空のDataTable インスタンスがFill メソッドへの引数として渡されます。このメソッドが戻ってきたとき、DataTable インスタンスにはクエリされたデータが設定されています。Fill メソッドは、戻る前にデータソースからすべてのデータを取得する必要があるため、FreshBooksDataAdapter はFreshBooksDataReader よりも時間がかかります。
次の例は、Clients テーブルのEmail カラムとUsername カラムを選択します。
C#
string connectionString = "InitiateOAuth=GETANDREFRESH;OAuthClientId=MyClientId;OAuthClientSecret=MyClientSecret;CallbackURL=http://localhost:33333"; using (FreshBooksConnection connection = new FreshBooksConnection(connectionString)) { FreshBooksDataAdapter dataAdapter = new FreshBooksDataAdapter( "SELECT Email, Username FROM Clients", connection); DataTable table = new DataTable(); dataAdapter.Fill(table); Console.WriteLine("Contents of Clients."); foreach (DataRow row in table.Rows) { Console.WriteLine("{0}: {1}", row["Email"], row["Username"]); } }
VB.NET
Dim connectionString As String = "InitiateOAuth=GETANDREFRESH;OAuthClientId=MyClientId;OAuthClientSecret=MyClientSecret;CallbackURL=http://localhost:33333" Using connection As New FreshBooksConnection(connectionString) Dim dataAdapter As New FreshBooksDataAdapter("SELECT Email, Username FROM Clients", connection) Dim table As New DataTable() dataAdapter.Fill(table) Console.WriteLine("Contents of Clients.") For Each row As DataRow In table.Rows Console.WriteLine("{0}: {1}", row("Email"), row("Username")) Next End Using