DataReader を使用したクエリ
CData ADO.NET Provider for Google Contacts では、次の2つのネイティブ.NET インターフェースを使用して、GoogleContacts からデータを取得できます。GoogleContactsDataAdapter オブジェクトおよびGoogleContactsDataReader オブジェクト。各オブジェクトは同じタスク(データの取得)を実行しますが、実行方法が異なります。GoogleContactsDataAdapter オブジェクトはクエリに一致するすべてのデータを取得しますが、GoogleContactsDataReader オブジェクトは必要に応じてインクリメントしながら一部のデータだけをフェッチします。
GoogleContactsDataReader の使用
GoogleContactsDataReader はページ単位でデータを取得できるため、GoogleContactsDataAdapter よりもデータの取得が高速です。GoogleContactsDataReader からデータを読み取っていくと、必要に応じて一定の間隔で、データソースからの結果の次のページが要求されます。このため、結果が高速に返されます。 次の例は、[My Contacts] テーブルからすべてのカラムを選択します。
C#
string connectionString = "InitiateOAuth=GETANDREFRESH;";
using (GoogleContactsConnection connection = new GoogleContactsConnection(connectionString)) {
GoogleContactsCommand cmd = new GoogleContactsCommand("SELECT * FROM [My Contacts]", connection);
GoogleContactsDataReader rdr = cmd.ExecuteReader();
while (rdr.Read()) {
Console.WriteLine(String.Format("\t{0} --> \t\t{1}", rdr["GivenName"], rdr["HomeEmailAddresses"]));
}
}
VB.NET
Dim connectionString As String = "InitiateOAuth=GETANDREFRESH;"
Using connection As New GoogleContactsConnection(connectionString)
Dim cmd As New GoogleContactsCommand("SELECT * FROM [My Contacts]", connection)
Dim rdr As GoogleContactsDataReader = cmd.ExecuteReader()
While rdr.Read()
Console.WriteLine([String].Format(vbTab & "{0} --> " & vbTab & vbTab & "{1}", rdr("GivenName"), rdr("HomeEmailAddresses")))
End While
End Using