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 = '[email protected]' ", 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 = '[email protected]'", connection) Dim rowsAffected As Integer = cmd.ExecuteNonQuery() End UsingYou 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 = '[email protected]'", 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 = '[email protected]'", connection) Dim rowsAffected As Integer = cmd.ExecuteNonQuery() End Using