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