Click here to Skip to main content
15,173,640 members
Articles / Programming Languages / C#
Article
Posted 21 Dec 2007

Stats

140.1K views
1.4K downloads
38 bookmarked

Connect the Excel Database from C# .Net

Rate me:
Please Sign up or sign in to vote.
2.92/5 (9 votes)
21 Dec 2007CPOL
It Explains how to make a connection to the Excel and how to get the data using C# .Net

Introduction

It is the simple program. it explains how to connect MS-Excel Database.

Background

Creating Table in Excel is very simple and easy. also fetch from Excel table is also very easy.

Using the code

For Connect the Excel, we have to use the normal 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\";";

Here 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)

Share

About the Author

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

Comments and Discussions

 
BugNot able to download Pin
ashwinikumarpawar7-Aug-19 21:49
Memberashwinikumarpawar7-Aug-19 21:49 
GeneralNot able to download Pin
Member 1225274514-Apr-16 9:11
MemberMember 1225274514-Apr-16 9:11 
Questioncode not downloaded Pin
PSV Ramana Kumar25-Jun-14 20:36
professionalPSV Ramana Kumar25-Jun-14 20:36 
QuestionDownload don't run! Pin
David Rocha de Almeida16-Dec-12 16:11
MemberDavid Rocha de Almeida16-Dec-12 16:11 
GeneralAnother way to get DataSet from Excel Pin
CikaPero20-Jul-10 0:01
MemberCikaPero20-Jul-10 0:01 
JokeUse the English for to be better grammers Pin
ilikc0de9-Feb-08 10:39
Memberilikc0de9-Feb-08 10:39 
GeneralRe: Use the English for to be better grammers Pin
aprilkacau29-Aug-10 11:18
Memberaprilkacau29-Aug-10 11:18 
GeneralAdditional information Pin
Michal Blazejczyk4-Jan-08 10:53
MemberMichal Blazejczyk4-Jan-08 10:53 

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.