输出列数取决于输入参数的数据流组件.SSIS 自定义数据流组件 [英] Data flow component with number of output columns depending on input parameter. SSIS custom data flow component
问题描述
我正在开发自定义数据流组件.我定义的自定义属性之一包含一个字符串,该字符串包含有关输出列数的信息,准确地说,它包含列的名称(可以是 4,也可以是 5,但也可以是 50).
I am developing a custom data flow component. One of the custom properties I define contains a string that has information regarding the number of output columns, to be precise, it contains the names of the columns (could be 4, could be 5 but could also be 50).
因此输出列的数量是可变的.我不知道如何(或者即使可能)让组件的输出列数根据输入而变化.
The number of output columns is therefore variable. I can't figure out how to (or even if it is possible) to have a component with a number of output columns that varies based on the input.
有人知道如何进行吗?谢谢
Does anyone have an idea of how to procede? Thanks
更新
好的.所以在设计时我会查看我的自定义属性并创建所需的列.我应该用哪种方法执行此操作?
Ok. So at design time I look into my custom properties and create the columns required. In which method should I do this?
我在 ProvideComponentProperties 中尝试过:
I tried this in ProvideComponentProperties:
this.fields_ = this.ComponentMetaData.CustomPropertyCollection["Fields"].Value.ToString().Split(new Char[] { ',' });
foreach (string _field in fields_)
{
IDTSOutputColumn100 _outputCol = ComponentMetaData.OutputCollection[0].OutputColumnCollection.New();
_outputCol.Name = _field;
_outputCol.SetDataTypeProperties(DataType.DT_STR, 20, 0, 0, 1252);
}
基本上 fields_ 拆分了这样的字符串:
Basically fields_ splits up a string that's like this:
PRVT_PLACE,OPT_IMPLIED_VOLATILITY_MID,OPT_IMPLIED_VOLATILITY_YEST
我想为每个字段创建一个输出列.
And for each field I want to create an output column.
然后我放下我的组件并设置 fields_ 属性,但我收到以下消息:
I then drop my component and set the fields_ property but I get the following message:
The name for "output column" "(93)" is blank and names cannot contain blanks.
只创建了一列,名称为空,而不是上面示例中的 4...
Only one column is created with a blank name instead of the 4 for the example above...
我做错了什么?
推荐答案
我终于找到了解决方案.这可能不是正确的做法,但它适合我的需要.
I have finally found a solution. It may not be the exact thing to do but it suits my need.
我覆盖了 OnOutputPathAttached 方法.在这种方法中,我查看我的 fields_ 属性并根据它们的数量添加列.
I overrode the OnOutputPathAttached method. In this method I look into my fields_ property and add the columns based on their number.
ComponentMetaData.OutputCollection[0].OutputColumnCollection.RemoveAll();
string[] fields = this.ComponentMetaData.CustomPropertyCollection["Fields"].Value.ToString().Split(new Char[] { ',' });
foreach (string _field in fields)
{
IDTSOutputColumn100 _outputCol = ComponentMetaData.OutputCollection[0].OutputColumnCollection.New();
_outputCol.Name = _field;
_outputCol.SetDataTypeProperties(DataType.DT_STR, 20, 0, 0, 1252);
}
base.OnOutputPathAttached(outputID);
这篇关于输出列数取决于输入参数的数据流组件.SSIS 自定义数据流组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!