我有一个 SSIS 包,它在脚本任务中创建字符串列表,然后在 Foreach 循环容器中使用另一个脚本任务来一次从列表中获取值并做一些工作。
问题是,正如您在最后一张图片中看到的那样,我无法在脚本任务中设置一个变量,该变量取决于另一个变量的值(参见第三张图片),因为包(?)分配了值“Microsoft. SqlServer.Dts.Runtime.Variable”,而不是我想要的 ConstantPart 变量的值。
这是第一个脚本任务的一些代码:
public void Main()
{
bool fireAgain = false;
string TaskName = Dts.Variables["System::TaskName"].ToString();
try
{
string formattedDate = DateTime.Now.ToString("ddMMMyy", CultureInfo.InvariantCulture).ToUpper();
string constantPart = Dts.Variables["User::ConstantPart"].ToString();
string item01 = formattedDate + constantPart + "01";
string item02 = formattedDate + constantPart + "02";
string item03 = formattedDate + constantPart + "03";
List<string> myList = new List<string>();
myList.Add(item01);
myList.Add(item02);
myList.Add(item03);
Dts.Variables["User::MyListObject"].Value = myList;
Dts.Events.FireInformation(3, TaskName, description: "Items added to collection: " + myList.Count.ToString()
, helpFile: "", helpContext: 0, fireAgain: ref fireAgain);
}
catch (Exception ex)
{
Dts.Events.FireError(18, TaskName, ex.Message, "", 0);
}
Dts.TaskResult = (int)ScriptResults.Success;
}
从第二个开始:
public void Main()
{
bool fireAgain = false;
string taskName = Dts.Variables["System::TaskName"].ToString();
try
{
string currentItem = (string) Dts.Variables["User::SingleItem"].Value;
Dts.Events.FireInformation(3, taskName, "Processing Item: " + currentItem, "", 0, ref fireAgain);
}
catch (Exception ex)
{
Dts.Events.FireError(18, taskName, "While processing item..." + ex.Message, "", 0);
throw;
}
Dts.TaskResult = (int)ScriptResults.Success;
}
你可以在这里找到解决方案。