ADO.NET Provider for AlloyDB

Build 23.0.8839

DataAdapter を使用したクエリ

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

AlloyDBDataAdapter の使用

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

次の例は、Orders テーブルのShipName カラムとShipCity カラムを選択します。

C#

string connectionString = "User=alloydb;Password=admin;Database=alloydb;Server=127.0.0.1;Port=5432";

using (AlloyDBConnection connection = new AlloyDBConnection(connectionString)) {
  AlloyDBDataAdapter dataAdapter = new AlloyDBDataAdapter(
  "SELECT ShipName, ShipCity FROM \"alloydb\".\"schema01\".Orders", connection);

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

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

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

VB.NET

Dim connectionString As String = "User=alloydb;Password=admin;Database=alloydb;Server=127.0.0.1;Port=5432"

Using connection As New AlloyDBConnection(connectionString)
  Dim dataAdapter As New AlloyDBDataAdapter("SELECT ShipName, ShipCity FROM \"alloydb\".\"schema01\".Orders", connection)

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

  Console.WriteLine("Contents of Orders.")

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

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