Binding Excel Data in Gridview

Lakn2
Posted by Lakn2 under ASP.NET category on | Points: 40 | Views : 4284
Hi,
Some times we have data in exel format so this code is useful to bind excel data in gridview then we can do maupulations in excel data.

public void bind()
{
string cnstr = "Provider=Microsoft.Jet.Oledb.4.0;Data Source=C:\\Book2.xls;" + "Extended Properties=Excel 8.0";
OleDbConnection oledbConn = new OleDbConnection(cnstr);
string strSQL = "SELECT * FROM [Sheet1$]";
OleDbCommand cmd = new OleDbCommand(strSQL, oledbConn);
DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}

Comments or Responses

Login to post response