У меня есть пакет SSIS, который вводит данные из плоского файла в таблицу базы данных SQL 2008. Каждый день третья сторона создает плоский файл (.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