4

Does anyone have any examples of using EzAPI with a flat file as the data source? All the examples in the documentation start with OleDB connections.

Specifically I can't work out how to define input and output columns.

Say, for instance, that I have a CSV file with columns for firstname, surname and age. I want to read this into SSIS, sort by age and write out to another text file.

According to this post How to use EzAPI FlatFile Source in SSIS? I need to define columns manually, but I can't get the suggested code to work.

If I do:

if (!pkg.Source.OutputColumnExists("col0"))
{

       pkg.Source.InsertOutputColumn("col0");

}

bool newColumnExists = pkg.Source.OutputColumnExists("col0");

newColumnExists is still false.

Community
  • 1
  • 1
Dave K
  • 1,845
  • 1
  • 11
  • 9
  • The element cannot be found in a collection. This error happens when you try to retrieve an element from a collection on a container during execution of the package and the element is not there. – Bilal lilla Jul 02 '13 at 16:22

1 Answers1

1

i think this link will help you : http://blogs.msdn.com/b/mattm/archive/2008/12/30/ezapi-alternative-package-creation-api.aspx

you will get to know how to create one.

if you want to add columns in flat file use this code:

 var flatFileCm = new EzFlatFileCM(this);
 flatFileCm.ConnectionString = file;

  foreach (var column in columns)
   {
    // Add a new Column to the Flat File Connection Manager
    var flatFileColumn = flatFileCm.Columns.Add();

    flatFileColumn.DataType = DataType.DT_WSTR;
    flatFileColumn.ColumnWidth = 255;

    flatFileColumn.ColumnDelimiter = columns.GetUpperBound(0) == Array.IndexOf(columns, column) ? "\r\n" : "\t";

    flatFileColumn.ColumnType = "Delimited";

    // Use the Import File Field name to name the Column
    var columnName = flatFileColumn as IDTSName100;
    if (columnName != null) columnName.Name = column;
 }
 flatFileCm.ColumnNamesInFirstDataRow = true; 
lipeiran
  • 526
  • 13
  • 33
Rahul Sharma
  • 453
  • 3
  • 10