Connecting To Excel 2007 files via C#

First of all we are declaring the ODBC namespace which we will use an Excel DNS; 

using System.Data.Odbc;

then we will write these codes for connecting to a specific Excel file;

String strConn = @"Dsn=Excel Files;dbq=excel_file_path;defaultdir=excel_file_dir;driverid=1046;maxbuffersize=2048;pagetimeout=5";
            OdbcConnection objConn = new OdbcConnection(strConn);
            objConn.Open();
            OdbcDataAdapter adp = new OdbcDataAdapter("select * from [Sheet1$]", objConn);
            DataSet ds = new DataSet();
            adp.Fill(ds);
            dataGridView1.DataSource = ds.Tables[0];
            objConn.Close();

Thats all by using these codes you have got the datas you wanted to...

Cheers;)

 

Ebook Download
View all
Learn
View all
Araf Global is a software consultancy company founded in 2016 focusing on cutting edge technologies.