This is a very short post containing a useful code snippet for writing to a SQL Server Integration Services (SSIS) variable from within a script task.
Imports Microsoft.SqlServer.Dts.Runtime
Public Class ScriptMain
Public Sub Main()
Dim vars As Variables
Dts.VariableDispenser.LockOneForWrite("vMyVar", vars)
vars(0).Value = "Hello World"
vars.Unlock()
Dts.TaskResult = Dts.Results.Success
End Sub
End Class
The other option is to place the variable name into ReadWriteVariables property of the script task...but doing it in code is the "proper" way to do it!
-Jamie
Update: As Kirk pointed out in his comment (below) both ways will work. I just like the coding method better. It gives you a sense of control f you know what I mean, you have explicit control over what is going on and at what stage the variable gets locked!