iloveorangesoda
Member
- Joined
- Feb 22, 2005
- Messages
- 7
- Programming Experience
- Beginner
I am trying the bulk import a csv file into a sql server 2005 table but I am getting errors with the datetime field. The csv file holds the date in the following format e.g. ccyymmdd - 20100401 and in the table the field is a datetime. I cannot change the file format or the table field format. The error when I bulk import is field is not a valid datetime. How can I resolve this? Sample code that I am using is as follows:
csv.Columns.Add("datetime", "currentEffDate")
bulkCopy = New SqlBulkCopy(conn, SqlBulkCopyOptions.Default, tran)
bulkCopy.DestinationTableName = "SqlTable"
bulkCopy.BulkCopyTimeout = 600
bulkCopy.ColumnMappings.Add("currentEffDate", "CurrentEffDate")
bulkCopy.WriteToServer(csv)
csv.Columns.Add("datetime", "currentEffDate")
bulkCopy = New SqlBulkCopy(conn, SqlBulkCopyOptions.Default, tran)
bulkCopy.DestinationTableName = "SqlTable"
bulkCopy.BulkCopyTimeout = 600
bulkCopy.ColumnMappings.Add("currentEffDate", "CurrentEffDate")
bulkCopy.WriteToServer(csv)