c# Excel skipping first row?

后端 未结 3 945
轻奢々
轻奢々 2021-01-18 08:32

I\'m importing an xls file using OleDbCommand to a ds. Problem I\'m having is during the foreach on my ds its skipping for first row. I can\'t figure out why. Any suggest

相关标签:
3条回答
  • 2021-01-18 09:01

    Change the connection string (as mentioned in comment) from:

    string cnn = string.Format( 
        "Provider=Microsoft.ACE.OLEDB.12.0;" +
        "data source={0}{1}{2};" +
        "Extended Properties=Excel 8.0;", 
        fileLocation, fileName, fileExtension);
    

    to:

    string cnn = string.Format( 
        "Provider=Microsoft.ACE.OLEDB.12.0;" +
        "data source={0}{1}{2};" +
        "Extended Properties=Excel 8.0;HDR=No", 
        fileLocation, fileName, fileExtension);
    
    0 讨论(0)
  • 2021-01-18 09:07

    Maybe you've told it to skip first row. I remember a property that sounds something like FirstRowIsHeader. I think if that is set to true, then it skips. this can be changed at point you create your connection

    0 讨论(0)
  • 2021-01-18 09:13

    Check your connection string. Most likely it contains:

    HDR=Yes
    

    which indicates that first row is a header

    0 讨论(0)
提交回复
热议问题