I'm trying to add new values to a variable (System.Object) inside a foreach loop container that is using that variable. How can i do that ?
To understand my flow :
first script i'm adding a value to that variable and its working fine.
But inside the loop when i'm trying to add new values to that variable its not working :(
I've tried this 2 codes:
DataTable myDataTable = new DataTable("LISTA_CONTACTOS");
myDataTable.Columns.Add(new DataColumn("columnText", typeof(string)));
DataRow myDataRow = myDataTable.NewRow();
myDataRow["columnText"] = "1";
myDataTable.Rows.Add(myDataRow);
Dts.Variables["User::LISTA_CONTACTOS"].Value = myDataTable;
Dts.TaskResult = (int)ScriptResults.Success;
DataTable dataTable = (DataTable)Dts.Variables["LISTA_CONTACTOS"].Value;
dataTable.Columns.Add(new DataColumn("contact_id", typeof(string)));
DataRow newRow = dataTable.NewRow();
newRow["contact_id"] = "8535939";
dataTable.Rows.Add(newRow);
Dts.Variables["LISTA_CONTACTOS"].Value = dataTable;
Dts.TaskResult = (int)ScriptResults.Success;
Think its something like that ...
Can anyone help me ?


I've just achieved this. I did the following:
Initialize your new
DataTableoutside of your ForLoop and assign it to the variable. The following steps are:Create a new Script task outside of the ForLoop:
Ensure that the SSIS variable you've created has ReadWite access in the script:
Inside the Script, initialize your new
DataTable. Add the columns you need. Then set your SSIS variable to theDataTablevariable:Inside your ForLoop, create a new Script. Ensure that the variable has ReadWrite access (like in step 2). In the code, you can then append rows onto your data table:
FYI: In step 3, I used a
Script Taskinside theControl Flow. In step 4, I used aScript Componentinside aData Flow. That explains the difference in function names and the way we access SSIS variables.