Tuesday, March 24, 2015

SqlBulkCopy inserting dates wrong

I'm adding stuff to a DataTable and then using SqlBulkCopy to bulk insert it. One of the things is a DateTime field. Specifically, I am putting in new DateTime(1900, 1, 1, date.Hour, date.Minute, 0); The problem is when I bulk copy this it ends up in the database as 1/1/2000 instead of 1/1/1900.

When initializing the DataTable i simply had to specify the type of the datetime.
dataTable.Columns.Add("JustTheTime", typeof(DateTime));

After explicitly specifying the type it's now inserting 1/1/1900 as expected.

No comments:

Post a Comment

There was an error in this gadget