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"; using (XMLConnection connection = new XMLConnection(connectionString)) { XMLCommand cmd = new XMLCommand("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] = "DataModel=Relational;URI=C:\people.xml" Using connection As New XMLConnection(connectionString) Dim cmd As New XMLCommand("SELECT Email, Username INTO [csv://NorthwindOData.txt] FROM [NorthwindOData] WHERE Email = 'ana.trujilo@northwind.org'", 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 = "DataModel=Relational;URI=C:\people.xml"; using (XMLConnection connection = new XMLConnection(connectionString)) { XMLCommand cmd = new XMLCommand("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] = "DataModel=Relational;URI=C:\people.xml" Using connection As New XMLConnection(connectionString) Dim cmd As New XMLCommand("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