NAGARAJA H I
NAGARAJA H I

Reputation: 149

How to access variables in ScriptComponent in a DataFlow task and assign to a local variable

I am trying to access the variable RowCount. However, I can't do : since its assign value as 0 to row count even if have a result set

var rowCount=this.Variables.RowCount;

Upvotes: 1

Views: 143

Answers (1)

userfl89
userfl89

Reputation: 4790

Where are you trying to access this variable, and are you trying to update it? SSIS variables can only be written to in the PostExecute method. To do this, start by adding the variable to the ReadWriteVariables field of the script component editor, then you can access this as done below.

Your variable is named rowCount. Are you looking to return the number of rows that go through the Data Flow Task? A Script Component is called once for each record in a Data Flow Task. To get the total number of records, use Row Count transformation instead and assign the variable to the result of this.

int rowCount;

public override void PreExecute()
{
    base.PreExecute();
    //get variable value before processing rows.
    rowCount = Variables.RowCount;
}

public override void PostExecute()
{
    base.PostExecute();
    //update variable after records have been procssed
    Variables.RowCount = rowCount;
}

Upvotes: 1

Related Questions