ADO.NET Provider for Email

Build 21.0.7930

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):

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
You can specify other file formats in the URI. The following example exports tab-separated values:

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) 2021 CData Software, Inc. - All rights reserved.
Build 21.0.7930