ADO.NET Provider for REST

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 = "DataModel=Relational;URI=C:\people.xml;Format=XML";

using (RESTConnection connection = new RESTConnection(connectionString)) {
  RESTCommand cmd = new RESTCommand("SELECT personal.name.first, personal.name.last INTO [csv://NorthwindOData.txt] FROM [NorthwindOData] WHERE personal.name.last = 'ana.trujilo@northwind.org' ", connection);
  int rowsAffected = cmd.ExecuteNonQuery();
} 

VB.NET

Dim connectionString As [String] = "DataModel=Relational;URI=C:\people.xml;Format=XML" 

Using connection As New RESTConnection(connectionString)
  Dim cmd As New RESTCommand("SELECT personal.name.first, personal.name.last INTO [csv://NorthwindOData.txt] FROM [NorthwindOData] WHERE personal.name.last = 'ana.trujilo@northwind.org'", 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 = "DataModel=Relational;URI=C:\people.xml;Format=XML";

using (RESTConnection connection = new RESTConnection(connectionString)) {
  RESTCommand cmd = new RESTCommand("SELECT * INTO [NorthwindOData] IN [csv://filename=c:/NorthwindOData.csv;delimiter=tab] FROM [NorthwindOData] WHERE personal.name.last = 'ana.trujilo@northwind.org'", connection);
  int rowsAffected = cmd.ExecuteNonQuery();
} 

VB.NET

Dim connectionString As [String] = "DataModel=Relational;URI=C:\people.xml;Format=XML" 

Using connection As New RESTConnection(connectionString)
  Dim cmd As New RESTCommand("SELECT * INTO [NorthwindOData] IN [csv://filename=c:/NorthwindOData.csv;delimiter=tab] FROM [NorthwindOData] WHERE personal.name.last = 'ana.trujilo@northwind.org'", connection)
  Dim rowsAffected As Integer = cmd.ExecuteNonQuery()
End Using

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