I am trying import some legacy CSV files into my database which were exported with bit/boolean values as 1s and 0s instead of True/False.
I'm required to interface with a system that expects DataRow
and hence I am using the DataTable.Row.Add(params object[] values)
overload which lets you pass in a array of objects which are then mapped into the columns, to create my DataRows
. The DataTable
does have the Columns
set up with a schema that matches the target database.
This all works fine for every column type except these bit/boolean values where it complains it can't convert with the following exception:
System.ArgumentException: 'String was not recognized as a valid Boolean.Couldn't store <1> in IsEnabled Column. Expected type is Boolean.'
I want to find a way to customize the conversion code so that it knows how to converts the numbers (stored as strings) into bools. Is there a way to do this?
Update: Specifically, I want to avoid manually converting the data in my object[]
array first, if possible.