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