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.json";
using (JSONConnection connection = new JSONConnection(connectionString)) {
JSONCommand cmd = new JSONCommand("SELECT personal.name.first, personal.name.last INTO [csv://NorthwindOData.txt] FROM [NorthwindOData] WHERE personal.name.last = '[email protected]' ", connection);
int rowsAffected = cmd.ExecuteNonQuery();
}
VB.NET
Dim connectionString As [String] = "DataModel=Relational;URI=C:\people.json"
Using connection As New JSONConnection(connectionString)
Dim cmd As New JSONCommand("SELECT personal.name.first, personal.name.last INTO [csv://NorthwindOData.txt] FROM [NorthwindOData] WHERE personal.name.last = '[email protected]'", 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.json";
using (JSONConnection connection = new JSONConnection(connectionString)) {
JSONCommand cmd = new JSONCommand("SELECT * INTO [NorthwindOData] IN [csv://filename=c:/NorthwindOData.csv;delimiter=tab] FROM [NorthwindOData] WHERE personal.name.last = '[email protected]'", connection);
int rowsAffected = cmd.ExecuteNonQuery();
}
VB.NET
Dim connectionString As [String] = "DataModel=Relational;URI=C:\people.json"
Using connection As New JSONConnection(connectionString)
Dim cmd As New JSONCommand("SELECT * INTO [NorthwindOData] IN [csv://filename=c:/NorthwindOData.csv;delimiter=tab] FROM [NorthwindOData] WHERE personal.name.last = '[email protected]'", connection)
Dim rowsAffected As Integer = cmd.ExecuteNonQuery()
End Using