Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I am Trying to import a Fixed Length File Using SSIS programatically.

My connectionManager code is

connectionManager = package.InnerObject.Connections.Add("FLATFILE");
 connectionManager.ConnectionString = "C:\FIXED.TXT";
 connectionManager.Name = "SSIS Connection Manager for Files";
 connectionManager.Description = string.Concat("SSIS Connection Manager");
connectionManager.Properties["ColumnNamesInFirstDataRow"].SetValue(connectionManager, TRUE);
connectionManager.Properties["RowDelimiter"].SetValue(connectionManager, "\r\n");
connectionManager.Properties["Format"].SetValue(connectionManager, "FixedWidth");
connectionManager.Properties["HeaderRowDelimiter"].SetValue(connectionManager, "\r\n");


and my column mapping code is
MIDL
RuntimeWrapper.IDTSConnectionManagerFlatFile90 flatFileConnection =
     connectionManager.InnerObject as RuntimeWrapper.IDTSConnectionManagerFlatFile90;

    RuntimeWrapper.IDTSConnectionManagerFlatFileColumn90 column;
    RuntimeWrapper.IDTSConnectionManagerFlatFileColumns90 columns;
    RuntimeWrapper.IDTSName90 name;


    DataTable schemaTable = DataSource.GetSchemaTable(); // get the schema table


    foreach (DataRow row in schemaTable.Rows)
    {   // iterate
        string colName = row["ColumnName"] as string;    // get the col name
        // now create a new column for the connection manager
        column = flatFileConnection.Columns.Add();       // if this is the last row
       // column.ColumnDelimiter = delimitedDataSource.HeaderRowDelimiter;
        if (schemaTable.Rows.IndexOf(row) == (schemaTable.Rows.Count - 1))
        {
            column.ColumnDelimiter =delimitedDataSource.HeaderRowDelimiter;
            //column.ColumnDelimiter = @delimitedDataSource.HeaderRowDelimiter;
        }

        column.ColumnType = "FixedWidth";
        column.TextQualified = delimitedDataSource.TextQualifier != null;
        flatFileConnection.ColumnNamesInFirstDataRow = true;
        column.ColumnWidth = 5;
        column.MaximumWidth = 5;
        column.DataType = RuntimeWrapper.DataType.DT_WSTR;
        column.DataPrecision = 0;
        column.DataScale = 0;

        name = (RuntimeWrapper.IDTSName90)column;
        name.Name = colName;
    }



This code is importing datas wrongly. Also importing the Header row

My file content is

VB
data1,data2,data3
111112222233333
444445555566666



but it is importing like this ,
data1 data2 data3
a3 1 11112 22223
3333 4444 45555

Can any one help me to solve this and import a fixed length file using SSIS programatically

Regards
Hari
Posted
Updated 17-Oct-10 21:44pm
v2

What do you want to do ?
Look if your file content is like this .

data1,data2,data3
111112222233333
444445555566666


then are your want to see the data in your db table like this

data1 data2 data3
11111 22222 33333
44444 55555 66666

where data1,data2 and data3 are your column name and
remaining two rows are your values .
 
Share this answer
 
Yes! This is what I need. Can you help me with this.

Hari
 
Share this answer
 
Hi
Got the solution. Column type of the last column should be delimited

Hari
 
Share this answer
 
Ok can you share the solution with me ?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900