populate output column in script component

10,045

A script component allows you access SSIS variables in the Variables collection, once you've added them to the read or read/write collection.

The syntax for doing so is

MyOutputBuffer.MyColumn = Variables.FILE_NAME;

A script task is different in that you would need to access the Value method and then cast to the resulting value from Object to the correct type.

There are two other ways of adding the value of FILE_NAME into your Data flow. The second and more SSIS-centric way would be to use a Derived Column Component with an expression like

@[User::FILE_NAME]

assuming that you've defined this as a new column named MyColumn and have a type like DT_WSTR(120)

The other, assuming this was a Flat File Source, is to go to the Advanced properties and include the filename as a column.

I blogged about the latter approaches under What is the name of current file if you're looking for a thrilling read.

Share:
10,045

Related videos on Youtube

user2841795
Author by

user2841795

Updated on June 04, 2022

Comments

  • user2841795
    user2841795 almost 2 years

    File_NAME is readonly variable MyColumn is output column I have File_Name as ReadOnlyVariable in Script Component and I want to store this as output to use later in the package. Created Output column (myColumn) in Inputs and Outputs. Now trying to populate myColumn as File_Name

    public override void CreateNewOutputRows()
    {
        MyOutputBuffer.AddRow();
        MyOutputBuffer.MyColumn = ??User::FILE_NAME
    }
    

    How to put File_Name variable in MyColumn?

    • Matt Rowland
      Matt Rowland almost 8 years
      Your question is unclear. What is FILE_NAME? What is MyColumn? What do you mean by "store this as output"?
    • user2841795
      user2841795 almost 8 years
      Question is edited now.