ADO.NET Provider for Odoo

Build 23.0.8839

DataAdapter を使用したクエリ

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

OdooDataAdapter の使用

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

次の例は、res_users テーブルのname カラムとemail カラムを選択します。

C#

string connectionString = "User=MyUser;APIToken=MyToken;URL=http://MyOdooSite/;Database=MyDatabase";

using (OdooConnection connection = new OdooConnection(connectionString)) {
  OdooDataAdapter dataAdapter = new OdooDataAdapter(
  "SELECT name, email FROM res_users", connection);

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

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

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

VB.NET

Dim connectionString As String = "User=MyUser;APIToken=MyToken;URL=http://MyOdooSite/;Database=MyDatabase"

Using connection As New OdooConnection(connectionString)
  Dim dataAdapter As New OdooDataAdapter("SELECT name, email FROM res_users", connection)

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

  Console.WriteLine("Contents of res_users.")

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

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