Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. OLE DB/JET and Excel - Reading Data, Error Handling

OLE DB/JET and Excel - Reading Data, Error Handling

Scheduled Pinned Locked Moved Database
databasehelpcsharpcomquestion
1 Posts 1 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mcljava
    wrote on last edited by
    #1

    I recently started a C# prototype using the OLE DB access method to read from a hefty Excel spreadsheet that we use at the office. The nice thing about OLE DB is you can read Excel worksheets pretty easily, and in block read style. H O W E V E R, when was the last time you saw a clean error free, perfectly formatted spreadsheet? That's where I am stuck. It seems the OLE DB driver/JET engine will happily retrieve the specified query range but it also supplies a null for any cell it doesn't like and considers to have an error. Is there a way to override this behavior and tell OLEDB through the DataSet or ExtendedProperties to retrive all data "as is" thus ignoring any cell errors? FYI, here is how I am reading a worksheet in one read. In my case I know there are roughly 330-370 rows per worksheet, so I specify a range of 400 rows: // open the JET connection OleDbConnection con = new OleDbConnection( connectionOpts ); con.Open(); // build the query string query = string.Format( "SELECT * FROM [{0}$[1]]", tableName, queryRange ); // fill the dataset OleDbDataAdapter oleAdapter = new OleDbDataAdapter(); oleAdapter.SelectCommand = new OleDbCommand( query, con ); DataSet ds = new DataSet(); int rowsProcessed = oleAdapter.Fill( ds, "data" ); // free up resources oleAdapter.Dispose(); oleAdapter.Close(); etc. Mike Luster CTI/IVR/Telephony SME

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups