ADO.NET Provider for Odoo

Build 20.0.7654

Querying with the DataAdapter

The CData ADO.NET Provider for Odoo implements two ADO.NET interfaces you can use to retrieve data from Odoo: OdooDataAdapter and OdooDataReader objects. Whereas OdooDataAdapter objects retrieve a single result set of all the data that matches a query, OdooDataReader objects fetch data in subset increments as needed.

Using the OdooDataAdapter

Use the adapter's Fill method to retrieve data from the data source. An empty DataTable instance is passed as an argument to the Fill method. When the method returns, the DataTable instance is populated with the queried data. Note that the OdooDataAdapter is slower than the OdooDataReader because the Fill method needs to retrieve all data from the data source before returning.

The following example selects the name and email columns of the res_users table:

C#

string connectionString = "User=MyUser;Password=MyPassword;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;Password=MyPassword;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) 2020 CData Software, Inc. - All rights reserved.
Build 20.0.7654