ADO.NET Provider for CSV

Build 23.0.8839

DataAdapter を使用したクエリ

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

CSVDataAdapter の使用

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

次の例は、NorthwindOData テーブルのEmail カラムとUsername カラムを選択します。

C#

string connectionString = "GenerateSchemaFiles=OnStart;URI=https://MyAPI;Location=C:\\MySchemaFolder;";

using (CSVConnection connection = new CSVConnection(connectionString)) {
  CSVDataAdapter dataAdapter = new CSVDataAdapter(
  "SELECT Email, Username FROM NorthwindOData", connection);

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

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

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

VB.NET

Dim connectionString As String = "GenerateSchemaFiles=OnStart;URI=https://MyAPI;Location=C:\\MySchemaFolder;"

Using connection As New CSVConnection(connectionString)
  Dim dataAdapter As New CSVDataAdapter("SELECT Email, Username FROM NorthwindOData", connection)

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

  Console.WriteLine("Contents of NorthwindOData.")

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

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