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