ADO.NET Provider for Tally

Build 23.0.8839

DataAdapter を使用したクエリ

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

TallyDataAdapter の使用

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

次の例は、Company テーブルのName カラムとAddress カラムを選択します。

C#

string connectionString = "Url='http://localhost:9000'";

using (TallyConnection connection = new TallyConnection(connectionString)) {
  TallyDataAdapter dataAdapter = new TallyDataAdapter(
  "SELECT Name, Address FROM Company", connection);

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

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

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

VB.NET

Dim connectionString As String = "Url='http://localhost:9000'"

Using connection As New TallyConnection(connectionString)
  Dim dataAdapter As New TallyDataAdapter("SELECT Name, Address FROM Company", connection)

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

  Console.WriteLine("Contents of Company.")

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

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