Click here to Skip to main content
15,886,519 members
Articles / Programming Languages / C#
Article

How to connect Excel DB using C# .Net

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
21 Dec 2007CPOL 39.9K   13   2
Connect the Excel Tables using C# .net
Screenshot - XLSDB

Introduction

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.

License

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


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

Comments and Discussions

 
Answerimport Excel files into DataGridView to Sql server Pin
Dinesh Ginagar5-Jun-15 0:17
Dinesh Ginagar5-Jun-15 0:17 
GeneralBetter way Pin
FilipKrnjic9-Jul-09 5:44
FilipKrnjic9-Jul-09 5:44 

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.