Wednesday, May 17, 2006

Read the Values from Excel File

Using Microsoft Excel Driver,we can read the values from Excel files.



DataSet ds = new DataSet();

string connstr = @"Driver={Microsoft Excel Driver
(*.xls)};DriverId=790;Dbq=D:\My.xls;DefaultDir=D:\sankar;";


OdbcConnection conn = new OdbcConnection(connstr);
conn.Open();
OdbcDataAdapter da = new OdbcDataAdapter("select * from [sheet1$]",conn);
da.Fill(ds);
da.Dispose();

DataGrid1.DataSource = ds;
DataGrid1.DataBind();

No comments: