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