SSIS Components for Email

Build 20.0.7587

SELECT INTO ステートメント

SELECT INTO ステートメントを使って、書式付きデータをファイルにエクスポートできます。

SQL クエリを使ったデータのエクスポート

次のクエリは、comma-separated values(CSV)ファイルフォーマットにデータをエクスポートします。

C#

String connectionString = "Port=993;Server=imap.gmail.com;Password=password;User=user;Protocol=IMAP;SMTP Port=587;SMTP Server=smtp.gmail.com;";

using (EmailConnection connection = new EmailConnection(connectionString)) {
  EmailCommand cmd = new EmailCommand("SELECT From, Subject INTO [csv://[INBOX].txt] FROM [[INBOX]] WHERE Subject = 'Test' ", connection);
  int rowsAffected = cmd.ExecuteNonQuery();
} 

VB.NET

Dim connectionString As [String] = "Port=993;Server=imap.gmail.com;Password=password;User=user;Protocol=IMAP;SMTP Port=587;SMTP Server=smtp.gmail.com;" 

Using connection As New EmailConnection(connectionString)
  Dim cmd As New EmailCommand("SELECT From, Subject INTO [csv://[INBOX].txt] FROM [[INBOX]] WHERE Subject = 'Test'", connection)
  Dim rowsAffected As Integer = cmd.ExecuteNonQuery()
End Using
URI で他のファイルフォーマットを指定できます。以下の例は、tab-separated values(TSV)にエクスポートします。

C#

String connectionString = "Port=993;Server=imap.gmail.com;Password=password;User=user;Protocol=IMAP;SMTP Port=587;SMTP Server=smtp.gmail.com;";

using (EmailConnection connection = new EmailConnection(connectionString)) {
  EmailCommand cmd = new EmailCommand("SELECT * INTO [[INBOX]] IN [csv://filename=c:/[INBOX].csv;delimiter=tab] FROM [[INBOX]] WHERE Subject = 'Test'", connection);
  int rowsAffected = cmd.ExecuteNonQuery();
} 

VB.NET

Dim connectionString As [String] = "Port=993;Server=imap.gmail.com;Password=password;User=user;Protocol=IMAP;SMTP Port=587;SMTP Server=smtp.gmail.com;" 

Using connection As New EmailConnection(connectionString)
  Dim cmd As New EmailCommand("SELECT * INTO [[INBOX]] IN [csv://filename=c:/[INBOX].csv;delimiter=tab] FROM [[INBOX]] WHERE Subject = 'Test'", connection)
  Dim rowsAffected As Integer = cmd.ExecuteNonQuery()
End Using

Copyright (c) 2020 CData Software, Inc. - All rights reserved.
Build 20.0.7587