Skip to content Skip to sidebar Skip to footer

Ssis Foreach With A List Of Simple Objects

re: SSIS Foreach Loop task with a Variable: I have this working for a List of primitive objects (e.g. a list of strings, as discussed in this question) But how do you configure an

Solution 1:

The Foreach Loop in SSIS is used for iterating over a list of objects. So, for the example above you have a one dimensional list, List<Dog>, as an input to the loop. To get the current item in the list you need to specify a variable mapping to index 0.

If you had a two dimensional list, lets say List<Dog,Owner> then you would retrieve the current Dog object by mapping a variable to index 0, and the current Owner by mapping to index 1.

Once you have the current object in a variable you can get its properties by casting it to the appropriate type in a Script Task. Inside the script you can call dog.Name and save it to another variable for use in other components.

This is an example of the Script Task code (C#) which retrieves the dog object from a variable, and then saves its Name and BestTrick to two different variables.

publicvoidMain()

       Dog d = (Dog) Dts.Variables["Dog"].Value;

       Dts.Variables["DogName"].Value = d.Name;
       Dts.Variables["DogTrick"].Value = d.BestTrick;

    }

Please note that you will have to make each variable you want to edit or read known to the Script Task in its properties

Post a Comment for "Ssis Foreach With A List Of Simple Objects"