Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 非常简单的ssis脚本转换,使对象引用未设置为对象的实例_Vb.net_Ssis - Fatal编程技术网

Vb.net 非常简单的ssis脚本转换,使对象引用未设置为对象的实例

Vb.net 非常简单的ssis脚本转换,使对象引用未设置为对象的实例,vb.net,ssis,Vb.net,Ssis,我有一个ssis包,它接受一个平面文件并将其转储到SQL。在此过程中,需要从150列中删除“-”和“.”。我已经使用脚本转换完成了这项工作 Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer) Dim column As IDTSInputColumn90 Dim rowType As Type = Row.GetType() Dim columnValue As Proper

我有一个ssis包,它接受一个平面文件并将其转储到SQL。在此过程中,需要从150列中删除“-”和“.”。我已经使用脚本转换完成了这项工作

    Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
    Dim column As IDTSInputColumn90
    Dim rowType As Type = Row.GetType()
    Dim columnValue As PropertyInfo

    For Each column In Me.ComponentMetaData.InputCollection(0).InputColumnCollection

        columnValue = rowType.GetProperty(column.Name)

        Dim strCol As String = columnValue.GetValue(Row, Nothing).ToString()
        If Not String.IsNullOrEmpty(strCol) Then
            strCol = strCol.Replace("-", "").Replace(".", "")
            columnValue.SetValue(Row, strCol, Nothing)
        End If
    Next
End Sub
但是,我在运行它时遇到以下错误

对象引用未设置为对象的实例。

at ScriptComponent_f20c21e11e3348378ef0bbe6b65e9c05.ScriptMain.Input0_ProcessInputRow(Input0Buffer Row)
at ScriptComponent_f20c21e11e3348378ef0bbe6b65e9c05.UserComponent.Input0_ProcessInput(Input0Buffer Buffer)
at ScriptComponent_f20c21e11e3348378ef0bbe6b65e9c05.UserComponent.ProcessInput(Int32 InputID, PipelineBuffer Buffer)
at Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.ProcessInput(Int32 inputID, PipelineBuffer buffer)
我不明白为什么会发生这种事。。有什么想法吗

编辑我发现这一行是问题所在

Dim strCol As String = columnValue.GetValue(Row, Nothing).ToString()

我能够让它为我的数据集工作。我跳过了对字符串类型的转换,只是将其保留为对象类型。这并不漂亮,但似乎能完成任务

Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
    Dim column As IDTSInputColumn90
    Dim rowType As Type = Row.GetType()
    Dim columnValue As PropertyInfo

    For Each column In Me.ComponentMetaData.InputCollection(0).InputColumnCollection

        columnValue = rowType.GetProperty(column.Name)
        Dim meta As Integer = column.ExternalMetadataColumnID
        Try
            Dim Obj As Object = columnValue.GetValue(Row, Nothing)
            If Not String.IsNullOrEmpty(Obj) Then
                Obj = Obj.Replace("-", "").Replace(".", "")
                columnValue.SetValue(Row, Obj.ToString(), Nothing)
            End If
        Finally
            ' Rejoice in our null-ness
        End Try
    Next
End Sub
源数据 从这些数据开始

SourceSSN,DestinationSSN,Amount
,111-11-0000,5000.00
111-22-3333,111-22-3334,5000.00
121-22-3333,121-22-3334,5000.00
123-22-3333,123-22-3334,5000.00
124-22-3333,124-22-3334,5000.00
上面的脚本实现了这一点


可能的副本不完全相同。我理解例外情况。。但在这种情况下,我看不到它,也不知道如何避免它。。我曾尝试将strCol预先定义为“bob”,但我认为将其设置为列的GetValue会导致悲伤。。我想不出怎么绕道,怎么绕道?某些设置为
。找出它是什么,然后修复它。我正在从平面文件中读取。。有些字段是空的。。我知道这一点,但我不知道如何在将字段分配给stringSSIS 2008或2005之前预先检查字段是否为空?我假设2005基于对
idtInputColumn90
的引用,但只是为了涵盖基础。Dim Obj As Object=columnValue.GetValue(Row,Nothing)仍然抛出引用错误如果您使用提供的源数据定义一个简单文件,它是否有效?另外,如果您有try块,则不应该抛出错误