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 DocEntry, DocType INTO [csv://Orders.txt] FROM [Orders] WHERE DocType = 'dDocument_Items'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 DocEntry, DocType INTO [csv://Orders.txt;delimiter=tab] FROM [Orders] WHERE DocType = 'dDocument_Items'
C#
String connectionString = "Url=http://localhost:50000/b1s/v1;User=username;Password=password;CompanyDB=dbname;"; using (SAPBusinessOneConnection connection = new SAPBusinessOneConnection(connectionString)) { SAPBusinessOneCommand cmd = new SAPBusinessOneCommand("SELECT DocEntry, DocType INTO [csv://Orders.txt] FROM [Orders] WHERE DocType = 'dDocument_Items' ", connection); int rowsAffected = cmd.ExecuteNonQuery(); }
VB.NET
Dim connectionString As [String] = "Url=http://localhost:50000/b1s/v1;User=username;Password=password;CompanyDB=dbname;" Using connection As New SAPBusinessOneConnection(connectionString) Dim cmd As New SAPBusinessOneCommand("SELECT DocEntry, DocType INTO [csv://Orders.txt] FROM [Orders] WHERE DocType = 'dDocument_Items'", 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:50000/b1s/v1;User=username;Password=password;CompanyDB=dbname;"; using (SAPBusinessOneConnection connection = new SAPBusinessOneConnection(connectionString)) { SAPBusinessOneCommand cmd = new SAPBusinessOneCommand("SELECT * INTO [Orders] IN [csv://filename=c:/Orders.csv;delimiter=tab] FROM [Orders] WHERE DocType = 'dDocument_Items'", connection); int rowsAffected = cmd.ExecuteNonQuery(); }
VB.NET
Dim connectionString As [String] = "Url=http://localhost:50000/b1s/v1;User=username;Password=password;CompanyDB=dbname;" Using connection As New SAPBusinessOneConnection(connectionString) Dim cmd As New SAPBusinessOneCommand("SELECT * INTO [Orders] IN [csv://filename=c:/Orders.csv;delimiter=tab] FROM [Orders] WHERE DocType = 'dDocument_Items'", connection) Dim rowsAffected As Integer = cmd.ExecuteNonQuery() End Using