ADO.NET Provider for Informix

Build 23.0.8839

DataAdapter を使用したクエリ

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

InformixDataAdapter の使用

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

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

C#

string connectionString = "Server=10.0.1.2;Port=50000;User=admin;Password=admin;Database=test";

using (InformixConnection connection = new InformixConnection(connectionString)) {
  InformixDataAdapter dataAdapter = new InformixDataAdapter(
  "SELECT Id, Author FROM [informix].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 = "Server=10.0.1.2;Port=50000;User=admin;Password=admin;Database=test"

Using connection As New InformixConnection(connectionString)
  Dim dataAdapter As New InformixDataAdapter("SELECT Id, Author FROM [informix].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