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