是否可以使用脚本任务更改SSIS包中变量的值?

时间:2018-07-23 17:14:00

标签: ssis

是否可以使用脚本任务更改SSIS包中变量的值?我有一个foreach循环容器,它不想读取int变量,但是我在脚本任务中使用了该变量,因此对于我要完成的任务,它必须是int。每次运行代码时,都会出现错误:“错误:分配给变量“ User :: empid”的值(字符串)的类型不同于当前变量类型(Int32)。变量在执行期间可能不会更改类型。变量类型是严格的,但对象类型的变量除外。”有没有人熟悉这样的错误?

     public void Main()
    {


        string filename;
        // string datepart;
        //bool FolderExistFlg;

        //filename = Dts.Variables["User::name"].Value.ToString();
        filename = System.IO.Path.GetFileName(Dts.Variables["User::name"].Value.ToString());
        // datepart = (filename.Substring(filename.Length - 12)).Substring(0, 8);


        string getEmployerId = filename.Split('_')[0];
        int employerId = Int32.Parse(Regex.Match(getEmployerId, @"\d+").Value);


        Dts.TaskResult = (int)ScriptResults.Success;

        Dts.Variables["User::empId"].Value = employerId;











    }

    #region ScriptResults declaration
    /// <summary>
    /// This enum provides a convenient shorthand within the scope of this class for setting the
    /// result of the script.
    /// 
    /// This code was generated automatically.
    /// </summary>
    enum ScriptResults
    {
        Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
        Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
    };
    #endregion

}

0 个答案:

没有答案
相关问题