using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
public partial class _Default : System.Web.UI.Page
{
OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Documents and Settings\prasad.b\Desktop\sample.xls;Extended Properties='Excel 12.0;HDR=YES;'");
OleDbDataAdapter ad;
DataSet dSet = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GridView1.DataSource = getDataFromExcel();
GridView1.DataBind();
}
}
public DataSet getDataFromExcel()
{
ad = new OleDbDataAdapter("Select * from [Sheet1$]", con);
dSet = new DataSet();
ad.Fill(dSet);
return dSet;
}
}