DateTime format mismatch on importing from Excel Sheet

后端 未结 10 2174
旧巷少年郎
旧巷少年郎 2020-12-17 21:36

I\'m importing data from an Excel sheet on to a DataTable using the following code:

OleDbConnection con = new OleDbConnection(\"Provider=Microso         


        
10条回答
  •  生来不讨喜
    2020-12-17 21:56

    When linking Excel spreadsheets in MS Access, a problem arises when a column has mixed data types. For example, if the first row in the column is "Text" and the remaining are Numeric, the Numeric fields will be formatted as Text and #Error out. Likewise with Dates and non-Dates mixed in the same column.

    There are some nice attempts at answers up there, but here is the simple solution to read these Mixed data types without a data type mismatch error:

    Try adding "IMEX=1" to your MS Access SQL, such as:

    SELECT Type, Width, Weight

    FROM [Excel 8.0;IMEX=1;DATABASE=C:\TEMP\MySpreadsheet.xls].MyExcelTable

    Thanks, Brian Jasmer

提交回复
热议问题