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