Accessing Excel Spreadsheet with C# occasionally returns blank value for some cells

后端 未结 10 2154
無奈伤痛
無奈伤痛 2020-12-11 02:43

I need to access an excel spreadsheet and insert the data from the spreadsheet into a SQL Database. However the Primary Keys are mixed, most are numeric and some are alpha-n

10条回答
  •  無奈伤痛
    2020-12-11 02:48

    Solution:

    1. You put HDR=No so that the first row is not considered the column header. Connection String: Provider=Microsoft.Jet.OLEDB.4.0;Data Source=FilePath;Extended Properties="Excel 8.0;HDR=No;IMEX=1";
    2. You ignore the first row and you acces the data by any means you want (DataTable, DataReader ect). You acces the columns by numeric indexes, instead of column names.

    It worked for me. This way you don't have to modify registers!

提交回复
热议问题