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

Ilkin EastPosted Jul 12, 2011, 12:59 AM
Tesekkurler Ibrahim Bey
Ibrahim ErsoyPosted Aug 14, 2007, 3:19 AM
here theres an example which can help u too try { OleDbConnection baglanti = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +file+ ";Excel 12.0;HDR=YES;"); baglanti.Open(); OleDbDataAdapter adp = new OleDbDataAdapter("select * from [" + Table+ "]", baglanti); DataSet ds2 = new DataSet(); adp.Fill(ds2); dataGridView1.DataSource = ds2.Tables[0]; } catch (StackOverflowException stack_ex2) { MessageBox.Show("(2007 Excel file) Stack Overflowed!" + "\n" + stack_ex2.Message); } catch (OleDbException ex_oledb2) { MessageBox.Show("An OleDb Error Thrown!" + "\n" + ex_oledb2.Message); }