This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Data; | |
using System.Data.OleDb ; | |
public partial class _Default : System.Web.UI.Page | |
{ | |
protected void Page_Load(object sender, EventArgs e) | |
{ | |
try | |
{ | |
string connStr = "provider=Microsoft.Jet.OLEDB.4.0;Data Source=ExcelFile.xls;Extended Properties=Excel 8.0;"; | |
OleDbConnection MyConnection; | |
DataSet ds; | |
OleDbDataAdapter MyCommand; | |
MyConnection = new OleDbConnection(connStr); | |
MyCommand = new OleDbDataAdapter("select * from [Sheet1$]", MyConnection); | |
ds = new System.Data.DataSet(); | |
MyCommand.Fill(ds); | |
MyConnection.Close(); | |
GridView1.DataSource = ds.Tables[0].DefaultView; | |
GridView1.DataBind(); | |
} | |
catch (Exception ex) | |
{ | |
Label1.Text = ex.ToString(); | |
} | |
} | |
} |