I have a DataTable which has 10 columns, and after I add some rows in it, I want to add it to the database using SqlBulkCopy.
My problem is that in the DataTable I have strings and some fields in the database are decimal and date respectively. Is there a way to convert them to the desired data types?
When programmatically adding columns to your DataTable, you can specify type:-
These will be honored when you perform the bulk copy.
EDIT
In response to user comment.
When populating the DataRow with information, an explicit conversion is only required if the source data doesn’t match the target field.
If the types are the same, you can just assign it.
e.g.