如何将数据集对象存储到数据类型对象的包变量中? [英] How can I store a dataset object into a package variable of data type object?

查看:32
本文介绍了如何将数据集对象存储到数据类型对象的包变量中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将数据集对象存储到数据类型为 Object 的包变量中,并从脚本任务中将其分配回另一个数据集对象?

How can I store dataset object into a package variable of data type Object and assigning it back to another Dataset object from within a script task?

推荐答案

这是我之前回答的代码示例.它展示了如何在脚本任务中从对象变量填充 OleDB 数据适配器.您可以使用数据流任务中的记录集目标将记录集存储到对象变量中.
如何访问脚本任务内的记录集变量

Here is a code example from a previous answer of mine. It shows how, in a script task, you can fill an OleDB Data Adapter from an Object Variable. You can store recordsets into object variables by using the recordset destination in a dataflow task.
How to access a Recordset Variable inside a Script Task

为了进一步扩展我在其他答案中在脚本中所做的工作,如果您已经操作了对象变量中的行并希望将新结果保存到对象变量中以供进一步处理,您可以在接近尾声时执行以下操作你的过程.Dts.Variables("rsRecipients").Value = dt

To further extend what I did in the script from my other answer, if you have manipulated the rows in your object variable and want to save the new results into the object variable for further processing, you can do the following near the end of your process. Dts.Variables("rsRecipients").Value = dt

此示例位于:从脚本任务中更新 Foreach 容器中使用的 SSIS 对象变量
示例 #2 中的代码:

An example of this is located at: Update SSIS Object Variable Used In Foreach Conainer From Script Task
Code from example #2:

Public Sub Main()
Dim Header As String
Dim Body As String
Dim Footer As String
Header = "blah"

Footer = "blah"

Try
    Dim olead As New Data.OleDb.OleDbDataAdapter
    Dim dt As New Data.DataTable
    olead.Fill(dt, Dts.Variables("rsRecipients").Value)

    For Each row As Data.DataRow In dt.Rows
        If UCase(Trim(row("EmployeeCode").ToString())) = UCase(Trim(Dts.Variables("colEmployeeCode").Value.ToString())) Then
            Body = Body + "Label: " + Trim(row("colum").ToString()) + System.Environment.NewLine
            row.Delete()
        End If
    Next
    Dts.Variables("rsRecipients").Value = dt
    Dts.Variables("EmailMessage").Value = Header + Body + Footer
    Dts.TaskResult = Dts.Results.Success
Catch ex As Exception
    Dts.TaskResult = Dts.Results.Failure
End Try

结束子

olead.Fill(dt, Dts.Variables("rsRecipients").Value) 从记录集变量中读入.行 Dts.Variables("rsRecipients").Value = dt 将数据集写回到一个变量中(在本例中是同一个变量,但是如果你想,你可以将它写到一个不同的变量中).将数据集加载到对象变量的其他方法包括在数据流任务中使用记录集目标,或使用 sql 任务并通过在对话框中的结果集字段上选择完整结果集来将完整结果集设置为变量,然后设置输出到对象类型的变量.

The line olead.Fill(dt, Dts.Variables("rsRecipients").Value) reads in from a recordset variable. The line Dts.Variables("rsRecipients").Value = dt writes the dataset back out to a variable (in this case the same one, however you could write it to a different variable if you wanted to). The other ways to load a dataset into a object variable include using the recordset destination in a dataflow task, or using a sql task and setting the full resultset to a variable by choosing full result set on the result set field in the dialog, then setting the output to go to a variable of type object.

这篇关于如何将数据集对象存储到数据类型对象的包变量中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆