using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string asd = "C:\Users\owlcity33\Desktop\222.xlsx";
DataSet ds = ExcelToDS(asd);
DataTable dt = ds.Tables[0];
GridView1.DataSource = dt;
GridView1.DataBind();
}
public DataSet ExcelToDS(string Path)
{
string strConn = "Provider=Microsoft.Ace.OleDb.12.0;" + "data source=" + Path + ";Extended Properties='Excel 12.0; HDR=Yes; IMEX=1'";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
string strExcel = "";
OleDbDataAdapter myCommand = null;
DataSet ds = null;
strExcel = "select * from [sheet1$]";
myCommand = new OleDbDataAdapter(strExcel,strConn);
ds = new DataSet();
myCommand.Fill(ds, "table1");
return ds;
}
protected void Button1_Click(object sender, EventArgs e)
{
string PH = FileUpload1.PostedFile.FileName.ToString();
DataSet ds1= ExcelToDS(PH);
DataTable dt1 = ds1.Tables[0];
g.DataSource = dt1;
g.DataBind();
}
}