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