Object Variable in script tasks

2020-07-30 00:53发布

问题:

In my package, I have an Execute Sql Task that sets the result set to a User variable. I then have a c# script task that needs to reference this User variable as a result set. I need the entire result set sent into my script tasks as the web service I am calling needs the entire result set in one shot.

This is the current code I am testing with. It isn't much as I am still trying to figure out where to go with it.

Any help with this is greatly appreciated

public void Main()
{
    Variable resultSet = Dts.Variables["User::ZBatch_Order_Export_ResultSet"];

    Dts.TaskResult = (int)ScriptResults.Success;
}

This is the update working code:

public void Main()
{
    DataTable dt = new DataTable();
    OleDbDataAdapter oleDa = new OleDbDataAdapter();

    oleDa.Fill(dt, Dts.Variables["User::ZBatch_Order_Export_ResultSet"].Value);

    foreach (DataRow row in dt.Rows)
    {
        Dts.Events
           .FireError(0, "ZBatch - Script Task", row["orderDate"]
           .ToString(), String.Empty, 0);
        // Do some Webservice magic
    }

    Dts.TaskResult = (int)ScriptResults.Success;
}

回答1:

So very close, to access the Value of a variable, you need to hit that property

public void Main()
{
    Variable resultSet = Dts.Variables["User::ZBatch_Order_Export_ResultSet"].Value;

    // do stuff here with resultSet and the webservice

    Dts.TaskResult = (int)ScriptResults.Success;


}