SSIS Components for Microsoft Project

Build 21.0.7867

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 = "user=myuseraccount;password=mypassword;URL=http://myserver/myOrgRoot;";

using (MicrosoftProjectConnection connection = new MicrosoftProjectConnection(connectionString)) {
  MicrosoftProjectCommand cmd = new MicrosoftProjectCommand("SELECT Id, Name INTO [csv://Projects.txt] FROM [Projects] WHERE Name = 'Tax Checker' ", connection);
  int rowsAffected = cmd.ExecuteNonQuery();
} 

VB.NET

Dim connectionString As [String] = "user=myuseraccount;password=mypassword;URL=http://myserver/myOrgRoot;" 

Using connection As New MicrosoftProjectConnection(connectionString)
  Dim cmd As New MicrosoftProjectCommand("SELECT Id, Name INTO [csv://Projects.txt] FROM [Projects] WHERE Name = 'Tax Checker'", 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 = "user=myuseraccount;password=mypassword;URL=http://myserver/myOrgRoot;";

using (MicrosoftProjectConnection connection = new MicrosoftProjectConnection(connectionString)) {
  MicrosoftProjectCommand cmd = new MicrosoftProjectCommand("SELECT * INTO [Projects] IN [csv://filename=c:/Projects.csv;delimiter=tab] FROM [Projects] WHERE Name =; 'Tax Checker'", connection);
  int rowsAffected = cmd.ExecuteNonQuery();
} 

VB.NET

Dim connectionString As [String] = "user=myuseraccount;password=mypassword;URL=http://myserver/myOrgRoot;" 

Using connection As New MicrosoftProjectConnection(connectionString)
  Dim cmd As New MicrosoftProjectCommand("SELECT * INTO [Projects] IN [csv://filename=c:/Projects.csv;delimiter=tab] FROM [Projects] WHERE Name =; 'Tax Checker'", connection)
  Dim rowsAffected As Integer = cmd.ExecuteNonQuery()
End Using

Copyright (c) 2021 CData Software, Inc. - All rights reserved.
Build 21.0.7867