解决方法
在回答之前,我不认为该列只包含LF,因为如果行分隔符是CRLF,则不会将其视为分隔符.所以它可能是CRLF,但我会给出两种情况的解决方案(CRLF或LF)
解
您可以通过以下步骤解决此问题:
>首先在Flat File连接管理器中添加一列(DT_STR类型和长度4000),因此您将每行视为一列.
>在数据流任务中,您必须添加用于修复文件结构的脚本组件.并将行拆分为列.
简单测试
ID;name;DOB;Notes;ClassID{CRLF} 1;John;2001-01-01;;1{CRLF} 2;Moh;2002-01-01;Very cool{LF} Genius;2{CRLF} 3;Ali;2000-01-01;Calm;2{CRLF}
>行分隔符= {CRLF}
>标题行分隔符= {CRLF}
>在DataFlow任务中,我将添加一个平面文件源,2个脚本组件,OLEDB目标
>在第一个脚本组件中,我将Column0标记为输入,我将添加5个输出列ID,名称,DOB,Notes,ClassID,我将输出同步输入设置为无
>在第一个脚本组件中,我将编写一个脚本,将每行存储在内存变量中,并在行完成且另一行存在时将其分配给输出行.
Dim strLine As String = String.Empty Dim strDelimiter As String = ";" Public Sub EmptyMemoryVariables() strLine = String.Empty End Sub Public Sub AssignMemoryVariablesToOutput() With Output0Buffer .AddRow() .NewRow = strLine End With End Sub Public Function AreVariablesEmpty() As Boolean If strLine = "" Then Return True Else Return False End If End Function Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer) Dim strColumns As String() = Row.Column0.Split(CChar(strDelimiter)) If strColumns.Length = 5 Then If Not AreVariablesEmpty() Then AssignMemoryVariablesToOutput() EmptyMemoryVariables() End If strLine = Row.Column0 AssignMemoryVariablesToOutput() EmptyMemoryVariables() Else If strLine.Split(CChar(strDelimiter)).Length = 5 Then AssignMemoryVariablesToOutput() EmptyMemoryVariables() End If strLine &= Row.Column0 End If
>在第二个脚本组件中,我将每行拆分为列
Dim strDelimiter As String = ";" Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer) Dim strColumns As String() = Row.NewRow.Split(CChar(strDelimiter)) Row.ID = strColumns(0) Row.NAME = strColumns(1) Row.DOB = strColumns(2) Row.NOTES = strColumns(3) Row.CLASSID = strColumns(4) End Sub