Accessing SSIS script component output buffer progamatically

  • We have a script component with 110 output columns - MsgFld1, MsgFld2, ...... MsgFld110

    The script component takes an input string along with some meta data and passes that to a .net assembly. Data is returned in the form of a .net Dictionary<int><String> key-value pairs. I need to map these key-value pairs to the output columns, key1 to MsgFld1 key2 to MsgFld2 ..... key 110 to MsgFld110

    Initially we only had 10 fields and just used If statement to check the dictionary for a value and stuck that value in the next field. Regardless of how many key value pairs there were it still ran all 10 if statements. now we are looking at 110 if statements doing the same thing.

    does anyone know how to access the output columns programatically and be able to set the column value? I'm thinking this functionality is not available, but I may have missed something.

    The script component does not have a synchronous input so I'm calling the add row method of the outputbuffer.

    Sure would be nice if I could do something like outputbuffer.Column[ID] = dict.value[x]) in a foreach loop.

  • Well I knocked 220 lines of code (110 IF statements) down to 4 lines of code using Reflection.

    Basically I needed to populate up to 110 output fields in a script component, it varied depending on the input data.

    I was getting a key value pair dictionary from a .net assembly we wrote.

    In the script component had to assign each output field like the following

    If(ParsedMessage.TryGetValue(1, out msgValue))

    {

    OutputoBuffer.MsgField1 = msgValue;

    }

    If(ParsedMessage.TryGetValue(2, out msgValue))

    {

    OutputoBuffer.MsgField2 = msgValue;

    }

    ....

    .... for all 110 fields

    Using Reflection this was accomplished by:

    Type outPutType = Output0Buffer.GetType();

    foreach (var m in parsedMessage)

    {

    var propInfo = outPutType.GetProperty("MsgField" + m.Key.ToString());

    propInfo.SetValue(Output0Buffer, m.Value.ToString(), null);

    }

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply