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):
SELECT ParentId, Total INTO [csv://Orders.txt] FROM [Orders] WHERE ParentId = '3'You can specify other formats in the file URI. The possible delimiters are tab, semicolon, and comma with the default being a comma. The following example exports tab-separated values:
SELECT ParentId, Total INTO [csv://Orders.txt;delimiter=tab] FROM [Orders] WHERE ParentId = '3'
C#
String connectionString = " Url=http://localhost/woocommerce/;ConsumerKey=ck_ec52c76185c088ecaa3145287c8acba55a6f59ad;ConsumerSecret=cs_9fde14bf57126156701a7563fc87575713c355e5;"; using (WooCommerceConnection connection = new WooCommerceConnection(connectionString)) { WooCommerceCommand cmd = new WooCommerceCommand("SELECT ParentId, Total INTO [csv://Orders.txt] FROM [Orders] WHERE ParentId = '3' ", connection); int rowsAffected = cmd.ExecuteNonQuery(); }
VB.NET
Dim connectionString As [String] = " Url=http://localhost/woocommerce/;ConsumerKey=ck_ec52c76185c088ecaa3145287c8acba55a6f59ad;ConsumerSecret=cs_9fde14bf57126156701a7563fc87575713c355e5;" Using connection As New WooCommerceConnection(connectionString) Dim cmd As New WooCommerceCommand("SELECT ParentId, Total INTO [csv://Orders.txt] FROM [Orders] WHERE ParentId = '3'", 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 = " Url=http://localhost/woocommerce/;ConsumerKey=ck_ec52c76185c088ecaa3145287c8acba55a6f59ad;ConsumerSecret=cs_9fde14bf57126156701a7563fc87575713c355e5;"; using (WooCommerceConnection connection = new WooCommerceConnection(connectionString)) { WooCommerceCommand cmd = new WooCommerceCommand("SELECT * INTO [Orders] IN [csv://filename=c:/Orders.csv;delimiter=tab] FROM [Orders] WHERE ParentId = '3'", connection); int rowsAffected = cmd.ExecuteNonQuery(); }
VB.NET
Dim connectionString As [String] = " Url=http://localhost/woocommerce/;ConsumerKey=ck_ec52c76185c088ecaa3145287c8acba55a6f59ad;ConsumerSecret=cs_9fde14bf57126156701a7563fc87575713c355e5;" Using connection As New WooCommerceConnection(connectionString) Dim cmd As New WooCommerceCommand("SELECT * INTO [Orders] IN [csv://filename=c:/Orders.csv;delimiter=tab] FROM [Orders] WHERE ParentId = '3'", connection) Dim rowsAffected As Integer = cmd.ExecuteNonQuery() End Using