OLEDB query to fetch all column except few exceptional columns

0

I'm trying to read excel data into datatable object.But, some columns in excel is has corrupted data specifically of type DATE .

excel:

I'm using VB code to read the data with

  1. OLEDB Connection

    dtData = objExcelReader.ReadWorksheet(strFilePath.ToString, "select * from sheet1$", True)
    

With this code I get 'Not a legal OleAut date' error.

  1. With ExcelReader,

    objExcelReader = New ExcelIO.ExcelReader
    objExcelReader.UseHeaders = True
    objExcelReader.AllowSpacesInColumnName = blnAllowSpacesInColumnName
    objExcelReader.ReadFormatting = True
    objExcelReader.TrimStrings = True
    objExcelReader.ClearColumnDatatypes()    
    objExcelReader.DefaultStartRow = intStartRow
    dtData = objExcelReader.Read(strFilePath.ToString, thisApplication, strInputSheetName)
    

I get exception - 'Out of present range. (Exception from HRESULT: 0x8002000A (DISP_E_OVERFLOW))'

  1. Using range in query, I'm able to fetch records. I need to include multiple range in that case.

    dtData = objExcelReader.ReadWorksheet(strFilePath.ToString, "select * from sheet1$O:AK", True)
    

Can someone help me to include multiple range here like A:K & O:AK

Or to fix any of above mentioned issues and ignore those exceptional column.

excel
vb.net
oledb
asked on Stack Overflow Dec 14, 2017 by user1972432 • edited Dec 14, 2017 by Pᴇʜ

1 Answer

0
  1. Try not to put column containing dates in the first column of table.
  2. Sort data in that way that data column has data (with proper data format) in the fist row.
  3. See more on corrupt data formats here: https://dutchgemini.wordpress.com/2011/04/21/two-serious-flaws-with-excels-copyfromrecordset-method/
  4. Check this out how I have overcome corrupt formatting in open recordset. https://stackoverflow.com/a/33807584/1903793
answered on Stack Overflow Dec 14, 2017 by Przemyslaw Remin

User contributions licensed under CC BY-SA 3.0