我有一个 SSIS 包,它将平面文件中的数据输入到 SQL 2008 数据库表中。第 3 方每天生成平面文件 (.csv)。我需要删除的每个字段中都有前导空格。
我认为脚本组件可以解决问题?
我想让它遍历所有输入列和 LTrim(RTrim) 每一列的所有值。
我在这里找到了这段代码:http ://microsoft-ssis.blogspot.com/2010/12/do-something-for-all-columns-in-your.html
但是,我不知道如何将其更改为修剪值?
我尝试将“ValueOfProperty.ToUpper () ”更改为“ValueOfProperty.Trim () ”,但随后它导致组件“错误 30203:预期标识符...”出现错误
请帮忙??
这是我的 SSIS 数据流:
平面文件 > 数据转换 > 脚本组件 > OLE DB 目标
' This script adjusts the value of all string fields
Imports System
Imports System.Data
Imports System.Math
Imports System.Reflection ' Added
Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper
Imports Microsoft.SqlServer.Dts.Runtime.Wrapper
<microsoft .sqlserver.dts.pipeline.ssisscriptcomponententrypointattribute=".sqlserver.dts.pipeline.ssisscriptcomponententrypointattribute"> _
<clscompliant false="false"> _
Public Class ScriptMain
Inherits UserComponent
' Method that will be started for each record in you dataflow
Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
' Use Reflection to loop through all the properties of Row:
' Example:
' Row.Field1 (String)
' Row.Field1_IsNull (Boolean)
' Row.Field2 (String)
' Row.Field2_IsNull (Boolean)
Dim p As PropertyInfo
For Each p In Row.GetType().GetProperties()
' Do something for all string properties: Row.Field1, Row.Field2, etc.
If p.PropertyType Is GetType(String) Then
' Use a method to set the value of each String type property
' Make sure the length of the new value doesn't exceed the column size
p.SetValue(Row, DoSomething(p.GetValue(Row, Nothing).ToString()), Nothing)
End If
Next
End Sub
' New function that you can adjust to suit your needs
Public Function DoSomething(ByVal ValueOfProperty As String) As String
' Uppercase the value
ValueOfProperty = ValueOfProperty.ToUpper() 'Maybe change this to Trim()?
Return ValueOfProperty
End Function
End Class