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