将多值列拆分为多个记录

时间:2019-07-12 14:50:43

标签: vb.net ssis split etl script-component

我正在尝试将多值列拆分为ssis脚本组件中的多个记录。我有一栏是演员的名字,另一栏是他们的主演电影(用逗号隔开)。现在,我想拆分信息,以便每个原始文件都包含演员的姓名和仅一部电影的标题。我正在使用下面的代码,但它有问题。有谁能够帮助我?

我使用找到的代码,仅将输入和输出更改为西里尔字母,以适应程序的语言。

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 Вход0_ProcessInputRow(ByVal Row As Вход0Buffer)

        ' This array would hold the single numeric values after you tokenize the input column '
        Dim inputNumericValuesArray As Array
        ' This varibale would hold one value from the array during the loop '
        Dim currentNumericValue As String



        ' Tokenize the NumericValues column by splitting it based on a semicolon separator '
        inputNumericValuesArray = Row.ПреобразованиеданныхПреобразованиевЮникодknownForTitles.Split(","c)



        ' Loop on the retrieved tokens adding each in a new row '
        For Each currentNumericValue In inputNumericValuesArray
            ' Create a new row '
            Выход0Buffer.AddRow()



            ' Get the TaskName from the source row and assign it to the output row without any changes '
            Выход0Buffer.nconst = Row.ПреобразованиеданныхПреобразованиевЮникодnconst



            ' Parse the current numeric value as decimal '
            ' and assign it to the Numeric value of the output row '
            Выход0Buffer.knownForTitle = Decimal.Parse(currentNumericValue)
        Next
    End Sub

End Class

错误为0xC0047062。错误的完整说明如下:

  

Ошибка:0xC0047062вЗаполнениеname_title 1 1,Компонентскриптов   [23]:System.NullReferenceException:Ссылканаобъектнеуказываетна   экземпляробъекта。

1 个答案:

答案 0 :(得分:0)

在使用输入列之前,只需检查它们是否为空:

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 Вход0_ProcessInputRow(ByVal Row As Вход0Buffer)

        ' This array would hold the single numeric values after you tokenize the input column '
        Dim inputNumericValuesArray As Array
        ' This varibale would hold one value from the array during the loop '
        Dim currentNumericValue As String


        If Not Row.ПреобразованиеданныхПреобразованиевЮникодknownForTitles_IsNull Then

            ' Tokenize the NumericValues column by splitting it based on a semicolon separator '
            inputNumericValuesArray = Row.ПреобразованиеданныхПреобразованиевЮникодknownForTitles.Split(","c)



            ' Loop on the retrieved tokens adding each in a new row '
            For Each currentNumericValue In inputNumericValuesArray
                ' Create a new row '
                Выход0Buffer.AddRow()



                ' Get the TaskName from the source row and assign it to the output row without any changes '
                If Not Row.ПреобразованиеданныхПреобразованиевЮникодnconst_IsNull Then
                    Выход0Buffer.nconst = Row.ПреобразованиеданныхПреобразованиевЮникодnconst
                Else
                    Выход0Buffer.nconst)IsNull = True
                End If 


                ' Parse the current numeric value as decimal '
                ' and assign it to the Numeric value of the output row '
                Выход0Buffer.knownForTitle = Decimal.Parse(currentNumericValue)
            Next

        End If
    End Sub

End Class