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