ADO.NET Provider for CSV

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 = "GenerateSchemaFiles=OnStart;URI=https://MyAPI;Location=C:\\MySchemaFolder;";

using (CSVConnection connection = new CSVConnection(connectionString)) {
  CSVCommand cmd = new CSVCommand("SELECT Email, Username INTO [csv://NorthwindOData.txt] FROM [NorthwindOData] WHERE Email = 'ana.trujilo@northwind.org' ", connection);
  int rowsAffected = cmd.ExecuteNonQuery();
} 

VB.NET

Dim connectionString As [String] = "GenerateSchemaFiles=OnStart;URI=https://MyAPI;Location=C:\\MySchemaFolder;" 

Using connection As New CSVConnection(connectionString)
  Dim cmd As New CSVCommand("SELECT Email, Username INTO [csv://NorthwindOData.txt] FROM [NorthwindOData] WHERE Email = '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 = "GenerateSchemaFiles=OnStart;URI=https://MyAPI;Location=C:\\MySchemaFolder;";

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

VB.NET

Dim connectionString As [String] = "GenerateSchemaFiles=OnStart;URI=https://MyAPI;Location=C:\\MySchemaFolder;" 

Using connection As New CSVConnection(connectionString)
  Dim cmd As New CSVCommand("SELECT * INTO [NorthwindOData] IN [csv://filename=c:/NorthwindOData.csv;delimiter=tab] FROM [NorthwindOData] WHERE Email = '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