我有一个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()
答案 0 :(得分:1)
我能够让它为我的数据集工作。我跳过了转换为字符串类型,只是将其保留为对象类型based on what I assume to be the source of your script。它不漂亮,但它似乎完成了工作。
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
上面的脚本使这个