ADO.NET Provider for Odoo

Build 20.0.7654

SELECT INTO Statements

You can use the SELECT INTO statement to export formatted data to a file.

Data Export with an SQL Query

The following query exports data into a file formatted in comma-separated values (CSV):

C#

String connectionString = "User=MyUser;Password=MyPassword;URL=http://MyOdooSite/;Database=MyDatabase";

using (OdooConnection connection = new OdooConnection(connectionString)) {
  OdooCommand cmd = new OdooCommand("SELECT name, email INTO [csv://res_users.txt] FROM [res_users] WHERE company_name = 'Company Inc.' ", connection);
  int rowsAffected = cmd.ExecuteNonQuery();
} 

VB.NET

Dim connectionString As [String] = "User=MyUser;Password=MyPassword;URL=http://MyOdooSite/;Database=MyDatabase" 

Using connection As New OdooConnection(connectionString)
  Dim cmd As New OdooCommand("SELECT name, email INTO [csv://res_users.txt] FROM [res_users] WHERE company_name = 'Company Inc.'", connection)
  Dim rowsAffected As Integer = cmd.ExecuteNonQuery()
End Using
You can specify other file formats in the URI. The following example exports tab-separated values:

C#

String connectionString = "User=MyUser;Password=MyPassword;URL=http://MyOdooSite/;Database=MyDatabase";

using (OdooConnection connection = new OdooConnection(connectionString)) {
  OdooCommand cmd = new OdooCommand("SELECT * INTO [res_users] IN [csv://filename=c:/res_users.csv;delimiter=tab] FROM [res_users] WHERE company_name = 'Company Inc.'", connection);
  int rowsAffected = cmd.ExecuteNonQuery();
} 

VB.NET

Dim connectionString As [String] = "User=MyUser;Password=MyPassword;URL=http://MyOdooSite/;Database=MyDatabase" 

Using connection As New OdooConnection(connectionString)
  Dim cmd As New OdooCommand("SELECT * INTO [res_users] IN [csv://filename=c:/res_users.csv;delimiter=tab] FROM [res_users] WHERE company_name = 'Company Inc.'", connection)
  Dim rowsAffected As Integer = cmd.ExecuteNonQuery()
End Using

Copyright (c) 2020 CData Software, Inc. - All rights reserved.
Build 20.0.7654