如何将变量传递到脚本转换编辑器?

时间:2022-07-17 16:29:33

I would like to pass Variables from my package into Script Transformation Editor. How do I add this into my Row.Reference1 below?

我想将我的包中的变量传递给脚本转换编辑器。如何将其添加到下面的Row.Reference1中?

Here's the script that I use:

这是我使用的脚本:

Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper
Imports Microsoft.SqlServer.Dts.Runtime.Wrapper

Public Class ScriptMain
    Inherits UserComponent

Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)

        Row.Column1 = Tokenise(Row.Column0, "|", 1)
        Row.Column2 = Tokenise(Row.Column0, "|", 2)
        Row.Column3 = Tokenise(Row.Column0, "|", 3)
        Row.Column4 = Tokenise(Row.Column0, "|", 4)
        Row.Column5 = Tokenise(Row.Column0, "|", 5)
        Row.Column6 = Tokenise(Row.Column0, "|", 6)
        Row.Column7 = Tokenise(Row.Column0, "|", 7)
        Row.Column8 = Tokenise(Row.Column0, "|", 8)
        Row.Column9 = Tokenise(Row.Column0, "|", 9)
        Row.Column10 = Tokenise(Row.Column0, "|", 10)
        Row.Column11 = Tokenise(Row.Column0, "|", 11)
        Row.Column12 = Tokenise(Row.Column0, "|", 12)
        Row.Column13 = Tokenise(Row.Column0, "|", 13)
        Row.Column14 = Tokenise(Row.Column0, "|", 14)
        Row.Column15 = Tokenise(Row.Column0, "|", 15)
        Row.Column16 = Tokenise(Row.Column0, "|", 16)
        'Row.Reference1 = ???

    End Sub

Private Function Tokenise(ByVal input As String, ByVal delimiter As String, ByVal token As Integer) As String

        Dim tokenArray As String()
        tokenArray = input.Split(delimiter.ToCharArray) 'Split the string by the delimiter
        If tokenArray.Length < token Then 'Protect against a request for a token that doesn't exist
            Return ""
        Else
            Return tokenArray(token - 1)
        End If
    End Function
End Class

1 个解决方案

#1


On the "Script" page of the Script Transformation Editor, the last section is "Custom Properties". There are two properties: ReadOnlyVariables and ReadWriteVariables. Set those that are appropriate to a comma-separated list of the variables you want the script to reference.

在脚本转换编辑器的“脚本”页面上,最后一部分是“自定义属性”。有两个属性:ReadOnlyVariables和ReadWriteVariables。设置适合您希望脚本引用的变量的逗号分隔列表的那些。

When you click the "Edit Script" button, you'll find that the Variables class created in the ComponentWrapper.vb now has properties with the names of the variables. The read-only variables will exist as readonly properties; the ReadWrite variables will exist as properties with both a getter and a setter.

单击“编辑脚本”按钮时,您会发现在ComponentWrapper.vb中创建的Variables类现在具有包含变量名称的属性。只读变量将作为只读属性存在; ReadWrite变量将作为具有getter和setter的属性存在。

You then reference them as, for instance, Variables.TaskID.

然后,您将它们引用为,例如,Variables.TaskID。

#1


On the "Script" page of the Script Transformation Editor, the last section is "Custom Properties". There are two properties: ReadOnlyVariables and ReadWriteVariables. Set those that are appropriate to a comma-separated list of the variables you want the script to reference.

在脚本转换编辑器的“脚本”页面上,最后一部分是“自定义属性”。有两个属性:ReadOnlyVariables和ReadWriteVariables。设置适合您希望脚本引用的变量的逗号分隔列表的那些。

When you click the "Edit Script" button, you'll find that the Variables class created in the ComponentWrapper.vb now has properties with the names of the variables. The read-only variables will exist as readonly properties; the ReadWrite variables will exist as properties with both a getter and a setter.

单击“编辑脚本”按钮时,您会发现在ComponentWrapper.vb中创建的Variables类现在具有包含变量名称的属性。只读变量将作为只读属性存在; ReadWrite变量将作为具有getter和setter的属性存在。

You then reference them as, for instance, Variables.TaskID.

然后,您将它们引用为,例如,Variables.TaskID。