ADO.NET Provider for Amazon Redshift

Build 23.0.8839

DataAdapter を使用したクエリ

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

RedshiftDataAdapter の使用

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

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

C#

string connectionString = "User=admin;Password=admin;Database=dev;Server=examplecluster.my.us-west-2.redshift.amazonaws.com;Port=5439;";

using (RedshiftConnection connection = new RedshiftConnection(connectionString)) {
  RedshiftDataAdapter dataAdapter = new RedshiftDataAdapter(
  "SELECT ShipName, ShipCity FROM \"sales_db\".\"public\".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=admin;Password=admin;Database=dev;Server=examplecluster.my.us-west-2.redshift.amazonaws.com;Port=5439;"

Using connection As New RedshiftConnection(connectionString)
  Dim dataAdapter As New RedshiftDataAdapter("SELECT ShipName, ShipCity FROM \"sales_db\".\"public\".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