ADO.NET Provider for Query Federation

Build 23.0.8839

DataAdapter を使用したクエリ

CData ADO.NET Provider for Query Federation では、次の2つのネイティブ.NET インターフェースを使用して、Query Federation からデータを取得できます。QueryFederationDataAdapter オブジェクトおよびQueryFederationDataReader オブジェクト。各オブジェクトは同じタスク(データの取得)を実行しますが、実行方法が異なります。QueryFederationDataAdapter オブジェクトはクエリに一致するすべてのデータを取得しますが、QueryFederationDataReader オブジェクトは必要に応じてインクリメントしながら一部のデータだけをフェッチします。

QueryFederationDataAdapter の使用

アダプターのFill メソッドを使用して、データソースからデータを取得します。空のDataTable インスタンスがFill メソッドへの引数として渡されます。このメソッドが戻ってきたとき、DataTable インスタンスにはクエリされたデータが設定されています。Fill メソッドは、戻る前にデータソースからすべてのデータを取得する必要があるため、QueryFederationDataAdapter はQueryFederationDataReader よりも時間がかかります。

次の例は、Books テーブルのId カラムとAuthor カラムを選択します。

C#

string connectionString = "DatabaseConfiguration=C:\Users\Public\Documents\connections.json;DefaultCatalog=my_catalog";

using (QueryFederationConnection connection = new QueryFederationConnection(connectionString)) {
  QueryFederationDataAdapter dataAdapter = new QueryFederationDataAdapter(
  "SELECT Id, Author FROM [MySQLCatalog].[MySQLSchema].Books", connection);

  DataTable table = new DataTable();
  dataAdapter.Fill(table);

  Console.WriteLine("Contents of Books.");

  foreach (DataRow row in table.Rows) {
    Console.WriteLine("{0}: {1}", row["Id"], row["Author"]);
  }
}

VB.NET

Dim connectionString As String = "DatabaseConfiguration=C:\Users\Public\Documents\connections.json;DefaultCatalog=my_catalog"

Using connection As New QueryFederationConnection(connectionString)
  Dim dataAdapter As New QueryFederationDataAdapter("SELECT Id, Author FROM [MySQLCatalog].[MySQLSchema].Books", connection)

  Dim table As New DataTable()
  dataAdapter.Fill(table)

  Console.WriteLine("Contents of Books.")

  For Each row As DataRow In table.Rows
    Console.WriteLine("{0}: {1}", row("Id"), row("Author"))
  Next
End Using

Copyright (c) 2024 CData Software, Inc. - All rights reserved.
Build 23.0.8839