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