Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#

Connect the Excel Database from C# .Net

2.92/5 (9 votes)
21 Dec 2007CPOL 1   1.4K  
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)