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