如何在 SSIS 中使用 foreach 容器遍历完整结果集 [英] How to loop through full result set using foreach container in SSIS
问题描述
我在尝试使用 SSIS 从 excel 文件中检索完整结果集时遇到问题.
I encounter an issue when trying to use SSIS to retrieve a full result set from excel file.
我有两个变量
这是控制流中的仪表板
@CriteriaResult 返回 ADO 记录集
@CriteriaResult returns the ADO Recordset
@CriteriaID 是我尝试在刚返回的对象下循环的变量
@CriteriaID is the variable I try to loop through under the object I just returned
我遇到错误:分配给变量User::CriteriaID"的值类型与当前变量类型不同.变量在执行期间可能不会改变类型.变量类型是严格的,Object 类型的变量除外.
I encounter the error:The type of the value being assigned to variable "User::CriteriaID" differs from the current variable type. Variables may not change type during execution. Variable types are strict, except for variables of type Object.
我的数据是一列:1,2,3A,3B,3C...
My data is a column: 1,2,3A,3B,3C...
在线参考告诉我使用脚本任务来更改转换对象(@CriteriaResult),以便我可以使用其中的数据.
Online reference told me to use script task to change the convert object(@CriteriaResult) so I can use the data inside of it.
我的 VBA 代码是:
My VBA code is:
Public Sub Main()
Dim dt As Data.DataTable
Dim ds As Data.DataSet = CType(Dts.Variables("User::CriteriaID").Value, DataSet)
dt = ds.Tables(0)
Dts.TaskResult = ScriptResults.Success
End Sub
我可以知道我应该如何修改我的代码以使其正常工作吗?
May I know how should I revise my code to make it works?
推荐答案
您可以尝试这种方法来使用 ADO 枚举器进行迭代:1. 使用数据流任务导入记录集2. 在 ForEach 中使用 ADO 枚举器迭代记录集对象变量3.每次迭代将记录值保存到一个变量中
You can try this approach to iterate with an ADO enumerator: 1. Import to recordset with Data Flow Task 2. Iterate in ForEach with ADO Enumarator to recordset object variable 3. Each iteration saves record value to a variable
这是包截图
这篇关于如何在 SSIS 中使用 foreach 容器遍历完整结果集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!