フラット ファイルから SQL 2008 データベース テーブルにデータを入力する SSIS パッケージがあります。サード パーティは、フラット ファイル (.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