Click here to Skip to main content
13,299,495 members (70,568 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


13 bookmarked
Posted 21 Dec 2007

How to connect Excel DB using C# .Net

, 21 Dec 2007
Rate this:
Please Sign up or sign in to vote.
Connect the Excel Tables using C# .net
Screenshot - XLSDB


Get data from MS-Excel Using C# .Net

Using the code

Using this code you can get the data from MS-Excel. Its just a OLEDB connection as Follows
string Con_Str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DB_Path + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\";";

in this DB_Path is the location of the .XLS file.

"HDR=Yes;" indicates that the first row contains columnnames, 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.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Senthil Rajan
Software Developer Anadocs IT Solutions Pvt Ltd
India India
M.Senthil Rajan,
Software Engineer,
Anadocs IT Solutions,

You may also be interested in...


Comments and Discussions

Answerimport Excel files into DataGridView to Sql server Pin
Member 116679255-Jun-15 1:17
memberMember 116679255-Jun-15 1:17 
GeneralBetter way Pin
FilipKrnjic9-Jul-09 6:44
memberFilipKrnjic9-Jul-09 6:44 

Using OLEDB is very complicated way to get data from Excel with C#. I recommend you check out GemBox .NET component for XLS/CSV/XLSX/HTML files. It's free for commercial use if you need less then 150 rows.

GemBox Software - Easy and fast read/write Excel files for .NET

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.171207.1 | Last Updated 21 Dec 2007
Article Copyright 2007 by Senthil Rajan
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid