How to read Excel File in asp.net ?

//docpath is locaiton of Excel File from which we have to read Data

string con = @”Provider=Microsoft.Jet.OLEDB.4.0;Data Source=” + docpath + “;”;
con = con + @”Extended Properties=”"Excel 8.0;IMEX=1″”";
OleDbConnection oc = new OleDbConnection(con);
oc.Open();
OleDbCommand com = new OleDbCommand(“select * from [Sheet1$]“, oc);

//Sheet1 is the name of sheet in excel file from which you want to read data

OleDbDataAdapter da = new OleDbDataAdapter();
da.SelectCommand = com;
DataSet ds = new DataSet();
da.Fill(ds);
After this the data in excel will be stored in dataset ds. assign ds to any DataSource.

Leave a Reply