Posted by: R Manimaran | February 23, 2007

Loading Excel Data in DataGrid

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

EmpID    EMPName

1               Mani

2               Maran

In 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();


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s


%d bloggers like this: