简体   繁体   中英

DateTime saved as numeric value using SqlBulkCopy

I'm using SqlBulkCopy to save a read-only Excel sheet into a predefined SQL table.
There are several date columns in the sheet, but not all the rows have date values(empty and '#').
The corresponding columns types are varchar(20) and not smalldatetime, because otherwise I get an error that the data can not be converted.

After running SqlBulkCopy the dates are saved as numeric values in a pattern that I can't figure out.
For example:
31.12.2010 is saved as 40543
31.13.2011 is saved as 40908
30.6.2011 is saved as 40724

Now I have to present the date in web forms. The numeric values don't bother me as long as I can convert them back to date format for presenting in a GridView, but I don't know how.

Would appreciate any help with this.

尝试运行此查询:

SELECT CAST(CAST(YourVarcharDateColumn AS int) AS DateTime) FROM YourTable

I used the following:

DateTime.FromOADate(num).ToShortDateString();

where num is the numeric value of the date

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM