- Open Visual Studio 2005, and bring up the "Server Explorer" (View > Server Explorer)
- Next, click the icon to "Connect to Database"
- Choose "Microsoft Access Database File" as your data source
- We choose this because we want the .NET OLE DB Data Provider
- Click "OK" to get to the "Add Connection" dialog
- Browse to your Excel file
- You'll need to change your "Files of type" from "*.mdb" to "*.*"
- Next click the "Advanced..." button in the "Add Connection" dialog
- Locate "Advanced > Extended Properties"
- Paste in "Excel 8.0;HDR=Yes;IMEX=1"
According to www.ConnectionStrings.com:"HDR=Yes;" indicates that the first row contains column names, not data. "HDR=No;" indicates the opposite.
"IMEX=1;" tells the driver to always read "intermixed" (numbers, dates, strings etc) data columns as text. Note that this option might affect excel sheet write access negative.
- Click "OK" for the "Advanced Properties" dialog
- Click “Test Connection” to verify if you have everything set up correctly.
- Click "OK" for the "Add Connection" dialog
- You're all set, your Excel file should now appear in your database list.
Monday, October 22, 2007
Treat an Excel Workbook like a database with Visual Studio
I've been doing a lot of work with MS Excel 2003 lately. Specifically, I'm using it as a data source for an application. I recently learned Visual Studio 2005 can connect to an Excel workbook and treat it like a database.
I thought I would share my findings.
Here's how it's done:
Subscribe to:
Posts (Atom)