Posted by: R Manimaran | February 23, 2007

Loading Excel Data in Asp.net DataGrid

In Excel type in the Cells as given below and save the file in working folder of asp.net

EmpID    EMPName

1               Mani

2               Maran

In asp.net page add the namespace “using System.oledb;” and in Page load type this

OleDbConnection con=new OleDbConnection(“Provider=Microsoft.Jet.OLEDB.4.0;” +”Data Source=”+Server.MapPath(“~/Book1.xls”)+”;”+”Extended Properties=\”Excel 8.0;HDR=Yes\””);con.Open(); string Sql=”SELECT * FROM [Sheet1$]”;OleDbCommand cmd=new OleDbCommand (Sql,con);OleDbDataReader rdr=cmd.ExecuteReader();DataGrid1.DataSource=rdr;DataGrid1.DataBind();

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: