1

我创建了一个脚本任务,它读取一个 excel 文件并尝试更新连接管理器列的详细信息。

但是即使它运行没有错误,更改也不会“保存”,因此包会保留列的先前详细信息。

程序读取并存储信息后(ColumnNames[]、MaxWidth[] ..etc.)。

  1. 删除连接管理器的现有列:

    //INITIALIZE CONNECTION MANAGER OBJECTS
        ConnectionManager conn = Dts.Connections["Flat File Connection Manager"];
        var connectionFlatF = (Wrapper.IDTSConnectionManagerFlatFile100)conn.InnerObject;
    
    
        foreach (Wrapper.IDTSConnectionManagerFlatFileColumn100 column in connectionFlatF.Columns)
        {
            connectionFlatF.Columns.Remove(column);
        }
    
  2. 创建列并分配相关信息:

     for (i = 0; i < ColumnNames.Count; i++) {
    
            //Add column
            Wrapper.IDTSConnectionManagerFlatFileColumn100 flatfilecolumn = (Wrapper.IDTSConnectionManagerFlatFileColumn100)connectionFlatF.Columns.Add();
            //Add column details
            flatfilecolumn.ColumnType = "Delimited";
            flatfilecolumn.ColumnDelimiter = "\t";
            flatfilecolumn.ColumnWidth = 0;
            if (FinalType[i] == "[DT_STR]")
            {
                flatfilecolumn.MaximumWidth = Int32.Parse(MaxWidth[i]);
            }
            else if (FinalType[i] == "[DT_NUMERIC]")
            {
                flatfilecolumn.DataPrecision = Int32.Parse(Percision[i]);
                flatfilecolumn.DataScale = Int32.Parse(Scale[i]);
            }
    
            //Column name
            Wrapper.IDTSName100 columnname = (Wrapper.IDTSName100)flatfilecolumn;
            columnname.Name = ColumnNames[i];
    
    
        }
        conn.Dispose();
    
4

0 回答 0