我创建了一个脚本任务,该任务读取excel文件并尝试更新连接管理器列'细节。
但是即使它运行没有错误,也不会保存更改",因此包会保留列的先前详细信息。
程序读取并存储信息后(ColumnNames [],MaxWidth [] ..等。)。
删除连接管理器的现有列:
//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);
}
创建列并分配实际信息:
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();