I am using FlatFile Source Manager
--> Script COmponent as Trans
--> OLEDB destination
in my data flow.
Source reads all the rows from flat file and i want to skip the last row (Trailer record) updating the database.
Since it contains the NULL
values, database throws error.
Please assist me how to resolve this.
Regards, VHK
To ignore the last row you have to do the following steps:
DataFlow Task
(let's name it DFT RowCount
)
System.Int32
(Name: User::RowCount)
Flat File Source
(The file you want to import)
RowCount
component next to the Flat File Source
RowCount
result to the variable User::RowCount
DataFlow Task
(let's name it DFT Import
)
DFT Import
add a Flat File Source
(File you need to Import)
Script Component
next to the Flat File Source
User::RowCount
Variable to the Script ReadOnly Variables
DT_BOOL
(Name: IsLastRow
)In the Script Window write the following Script
Dim intRowCount As Integer = 0
Dim intCurrentRow As Integer = 0
Public Overrides Sub PreExecute()
MyBase.PreExecute()
intRowCount = Variables.RowCount
End Sub
Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
intCurrentRow += 1
If intCurrentRow = intRowCount Then
Row.IsLastRow = True
Else
Row.IsLastRow = False
End If
End Sub
Add a Conditional Split
Next to the Script Component
Split Rows using the Following Expression
[IsLastRow] == False
OLEDB Destination
next to the conditional SplitSide Note: if you want to ignore rows for another case (not last row) just change the script writen in the script component to meet your requirements
If your requirement is to avoid rows having null values in the flat file then you can follow below approach,
Conditional Split
component, and in the case expression
provide as !ISNULL(Column1) && !ISNULL(Column2)
(Column1 and Column2 can be as your wish. If your flat file has a column named, say ID
and it does not have null value except the last row, then you can use as !ISNULL(ID)
).Hope this would help you a lot.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With