SELECT INTO ステートメント
SELECT INTO ステートメントを使って、書式付きデータをファイルにエクスポートできます。
SQL クエリを使ったデータのエクスポート
次のクエリは、comma-separated values(CSV)ファイルフォーマットにデータをエクスポートします。
C#
String connectionString = "User=test;Password=test;URL=http://localhost:8166;";
using (QuickBooksConnection connection = new QuickBooksConnection(connectionString)) {
QuickBooksCommand cmd = new QuickBooksCommand("SELECT Id, Name INTO [csv://Customers.txt] FROM [Customers] WHERE Name = 'Cook, Brian' ", connection);
int rowsAffected = cmd.ExecuteNonQuery();
}
VB.NET
Dim connectionString As [String] = "User=test;Password=test;URL=http://localhost:8166;"
Using connection As New QuickBooksConnection(connectionString)
Dim cmd As New QuickBooksCommand("SELECT Id, Name INTO [csv://Customers.txt] FROM [Customers] WHERE Name = 'Cook, Brian'", connection)
Dim rowsAffected As Integer = cmd.ExecuteNonQuery()
End Using
URI で他のファイルフォーマットを指定できます。以下の例は、tab-separated values(TSV)にエクスポートします。
C#
String connectionString = "User=test;Password=test;URL=http://localhost:8166;";
using (QuickBooksConnection connection = new QuickBooksConnection(connectionString)) {
QuickBooksCommand cmd = new QuickBooksCommand("SELECT * INTO [Customers] IN [csv://filename=c:/Customers.csv;delimiter=tab] FROM [Customers] WHERE Name = 'Cook, Brian'", connection);
int rowsAffected = cmd.ExecuteNonQuery();
}
VB.NET
Dim connectionString As [String] = "User=test;Password=test;URL=http://localhost:8166;"
Using connection As New QuickBooksConnection(connectionString)
Dim cmd As New QuickBooksCommand("SELECT * INTO [Customers] IN [csv://filename=c:/Customers.csv;delimiter=tab] FROM [Customers] WHERE Name = 'Cook, Brian'", connection)
Dim rowsAffected As Integer = cmd.ExecuteNonQuery()
End Using