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