Thursday, January 20, 2011

Display Excel data in Gridview asp.net c#

string strConn = @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\Book1.xls;Extended Properties=""Excel 8.0;HDR=NO;IMEX=1""";

OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", strConn);

DataSet myDataSet = new DataSet();

myCommand.Fill(myDataSet,

"ExcelInfo");

GridView1.DataSource = myDataSet.Tables[

"ExcelInfo"].DefaultView;

GridView1.DataBind();

No comments: