Binding Excel Data in Gridview

Posted by Lakn2 under ASP.NET category on | Points: 40 | Views : 4125
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);
GridView1.DataSource = ds;

Comments or Responses

Login to post response