英文:
How to Access Parameters of User Variables in SSIS Script Task
问题
I have a variable [User::WorkOrderProductIdList]
in SSIS package containing records of a class object.
工单产品类
public class WorkOrderProduct
{
public Guid workOrderId;
public Guid workOrderProductId;
public static Guid WorkOrderId { get; set; }
public static Guid WorkOrderProductId { get; set; }
}
主要脚本任务
public override void InputWOProduct_ProcessInputRow(InputWOProductBuffer Row)
{
ArrayList wopList = new ArrayList();
WorkOrderProduct wop = new WorkOrderProduct();
wop.workOrderId = pWorkOrderID;
wop.workOrderProductId = pWorkOrderProductID;
wopList.Add(wop);
}
将 wopList 分配给 [User::WorkOrderProductIdList]
public override void PostExecute()
{
base.PostExecute();
Variables.WorkOrderProductIdList = this.wopList;
}
在另一个脚本任务中,它将 [User::WorkOrderProductIdList]
作为 ReadOnlyVariables
进行处理。
请问我该如何循环遍历 [User::WorkOrderProductIdList]
并提取每行的 workOrderId
和 workOrderProductId
值?
我看到我的 ArrayList [User::WorkOrderProductIdList]
包含记录和值,但在字段上使用 .
时没有可用的函数。
英文:
I have a variable [User::WorkOrderProductIdList]
in SSIS package containing records of a class object.
Work Order Product class
public class WorkOrderProduct
{
public Guid workOrderId;
public Guid workOrderProductId;
public static Guid WorkOrderId { get; set; }
public static Guid WorkOrderProductId { get; set; }
}
Main Script Task
public override void InputWOProduct_ProcessInputRow(InputWOProductBuffer Row)
{
ArrayList wopList = new ArrayList();
WorkOrderProduct wop = new WorkOrderProduct();
wop.workOrderId = pWorkOrderID;
wop.workOrderProductId = pWorkOrderProductID;
wopList.Add(wop);
}
Assign wopList to [User::WorkOrderProductIdList]
public override void PostExecute()
{
base.PostExecute();
Variables.WorkOrderProductIdList = this.wopList;
}
In another script task, it takes in [User::WorkOrderProductIdList]
as ReadOnlyVariables
.
May I know how can I loop through [User::WorkOrderProductIdList]
and extract the values of workOrderId
and workOrderProductId
for each row?
I saw that my ArrayList [User::WorkOrderProductIdList]
contains the records and values, but there are no functions when .
on the field.
答案1
得分: 1
Population
除了Intellisense问题,你最多只会在那里有1行
你正在使用数据流,其中包含一个作为转换的脚本组件。
在InputWOProduct_ProcessInputRow
中,该方法会为每个通过该组件的行触发:
每当新的行进入时,你将清空现有的ArrayList并重新初始化它。
相反,你需要在未显示的PreExecute方法中具有该变量的类范围,并在其中进行初始化逻辑。
ArrayList wopList;
// 或者,如果你想使用泛型
// List<WorkOrderProduct> wopList
public override void PreExecute()
{
base.PreExecute();
/*
* 在这里添加你的代码
*/
this.wopList = new ArrayList();
// 或者
// this.wopList = new List<WorkOrderProduct>();
}
Consumption
你使用ArrayList来保存数组的元素,但这是一个弱类型的列表。
英文:
Population
Intellisense issue aside, you'll only ever have at most 1 row in there
You are using a Data Flow and within that, you have a Script Component acting as a Transformation.
In InputWOProduct_ProcessInputRow
which fires for each row that passes through the component, you have
Every time a new row comes in, you are going to empty out the existing ArrayList and reinitialize it.
Instead, you need to have that variable at the class scope and have the initialization logic in the not-shown PreExecute method
ArrayList wopList;
// Or, if you wish to use the Generics
// List<WorkOrderProduct> wopList
public override void PreExecute()
{
base.PreExecute();
/*
* Add your code here
*/
this.wopList = new ArrayList();
// Or
// this.wopList = new List<WorkOrderProduct>();
}
Consumption
You use the ArrayList to hold the elements of your array but that is a weakly typed list.
> We don't recommend that you use the ArrayList class for new development. Instead, we recommend that you use the generic List<T> class.
When you're enumerating through it in your foreach loop, what is getting popped off the list is of type Object. Not only do I just "know" that, itellisense is telling you that all it knows is the type is Object because it's giving you the functions that everything has because they're all derived from Object.
Yes, the Watch window has inspection magic to show you what the values are but do you think the team that wrote the former is the same team that wrote the latter?
Since you "know" what the type should be, declare it as such.
foreach (WorkOrderProduct wopObj in ...
However, the next logical error, probably, is going to be in the accessing of
Variables.WorkOrderProductIdList
itself. Your snipped image there shows you're shredding out the array in the PreExecute
method. The sequence of operations is that the Data Flow is going to go through validation, then pre-execute sequences so at that point, it's going to shred the results of your array list and the value of wopObj_workOrderId
is going to be the last element of your array.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论