Import System.Data.OleDb(using System.Data.OleDb)in code behind file
Then in button onclick event write,
OleDbConnection connection = new OleDbConnection(@"Provider=Microsoft.Jet.OleDb.4.0;Data Source=D:\status.xls;Extended Properties=Excel 8.0");
OleDbCommand command = new OleDbCommand("SELECT * FROM [Sheet1$]", connection);
OleDbDataReader dr;
connection.Open();
dr = command.ExecuteReader(CommandBehavior.CloseConnection);
DataTable excelData = new DataTable("ExcelData");
excelData.Load(dr);
GridView1.DataSource = excelData;
GridView1.DataBind();
Then in button onclick event write,
OleDbConnection connection = new OleDbConnection(@"Provider=Microsoft.Jet.OleDb.4.0;Data Source=D:\status.xls;Extended Properties=Excel 8.0");
OleDbCommand command = new OleDbCommand("SELECT * FROM [Sheet1$]", connection);
OleDbDataReader dr;
connection.Open();
dr = command.ExecuteReader(CommandBehavior.CloseConnection);
DataTable excelData = new DataTable("ExcelData");
excelData.Load(dr);
GridView1.DataSource = excelData;
GridView1.DataBind();
Comments
Post a Comment