SSIS - 如何在脚本任务中访问 RecordSet 变量 [英] SSIS - How to access a RecordSet variable inside a Script Task

查看:22
本文介绍了SSIS - 如何在脚本任务中访问 RecordSet 变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何访问脚本任务中的 RecordSet 变量?

How do you access a RecordSet variable inside a Script Task?

推荐答案

在脚本选项卡上,确保将变量放在 readonlyvariables 或 readwritevariables 文本框中.

On the script tab, make sure you put the variable in either the readonlyvariables or readwritevariables text boxes.

这是一个简单的脚本,我用来将数据流中的错误(保存在 RecordSet 变量中)格式化为电子邮件正文.基本上我将记录集变量读入数据表并使用 for 循环逐行处理它.完成此任务后,我会检查 uvErrorEmailNeeded 的值,以确定是否有任何内容可以使用条件流程流连接器发送电子邮件.您还需要在 vb 脚本中添加对 system.xml 的引用.这是在 SQL 2005 中.

Here is a simple script that I use to format the errors in a data flow (saved in a RecordSet Variable) into the body of an email. Basically I read the recordset varialbe into a datatable and process it row by row with the for loops. After this task completes I examine the value of uvErrorEmailNeeded to determine if there is anything to email using a conditional process flow connector. You will also need to add a reference to system.xml in your vb script. This is in SQL 2005.

Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Imports System.Xml
Imports System.Data.OleDb


Public Class ScriptMain


    Public Sub Main()


        Dim oleDA As New OleDbDataAdapter
        Dim dt As New DataTable
        Dim col As DataColumn
        Dim row As DataRow
        Dim sMsg As String
        Dim sHeader As String


        oleDA.Fill(dt, Dts.Variables("uvErrorTable").Value)
        If dt.Rows.Count > 0 Then
            Dts.Variables("uvErrorEmailNeeded").Value = True
            For Each col In dt.Columns
                sHeader = sHeader & col.ColumnName & vbTab
            Next
            sHeader = sHeader & vbCrLf
            For Each row In dt.Rows
                For Each col In dt.Columns
                    sMsg = sMsg & row(col.Ordinal).ToString & vbTab
                Next
                sMsg = sMsg & vbCrLf
            Next
            Dts.Variables("uvMessageBody").Value = "Error task. Error list follows:" & vbCrLf & sHeader & sMsg & vbCrLf & vbCrLf
        End If

        Dts.TaskResult = Dts.Results.Success
    End Sub

End Class

这篇关于SSIS - 如何在脚本任务中访问 RecordSet 变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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