Just flip fromdt = Row.SampleDate
to
Row.SampleDate = fromdt
And your script should work but see below to simplify some if you want.
HOW TO DO IT WITHOUT A SCRIPT --see below for script method
You can make this a lot simpler for yourself if you use a Derived Column
transformation instead! The data conversion transformation doesn't work because it doesn't allow you to manipulate the value of the column, but rather only the data type. But in the derived column you can cut up the string and cast the result as a date.
So Source to Derived Column to Destination in your data flow.

In the derived column your add a new column and use the following as the expression (replacing DateString
with the name of your column
containing the date in ddMMyyyy
format)
Then use this as the Expression
:
(DT_DATE)(SUBSTRING(DateString,3,2) + "/" + (LEFT(DateString,2) + "/" + RIGHT(DateString,4)))
The (dt_date)
can be switched for another date format if you wish and that type cast will automatically set the Data Type
on the Derived Column
. Then in your destination
map the new derived column
to the destination column
instead of your original column from your source
.

That's it your done, no scripts.
HOW TO DO IT VIA A SCRIPT
To address the route if you wanted to stay with a script and perhaps inject some additional logic rather than simple conversion you can do it through a transformation
script component
in a your data flow task
. It will take place of the derived column
transformation above but essentially will do the same thing only through a script. I am putting steps in here that I am guessing you already know some of in case someone else stumbles on the post.
- Add the script component when you do choose "transformation" and connect it with you source
- Open Script component and go to the "
Inputs and Outputs
" section and add an output to hold the new column and set the datatype. A new column is necessary because you are changing data types

- go to "
Input Columns
" section and choose SampleDate
column

- go back to "
Script
" section and choose Visual Basic as your script language.
- Click Edit Script to begin your coding.
- Scroll down till you find the sub
Input0_ProcessInputRow(ByVal Row...
this is where you will put your code.
This code works:
Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
If Not Row.SampleDate_IsNull Then
Row.DerivedDate = DateTime.ParseExact(Row.SampleDate, "ddMMyyyy", System.Globalization.CultureInfo.InvariantCulture)
End If
End Sub
As @Shiva in comments suggested you could expand this and use TryParseExact or wrap it in a try catch block so that if parsing the date fails it would simply clear/remove the value from the record and the import will continue. I leave that up to you as handling invalid data is more a question of business requirements.