User Id :    Password :      New Member   Forgot Password
Topic: How to read data from excel sheet and show it on gridview ?
Senthilkcg
07 Oct 2011 at 01:29 AM

 How to read data from excel sheet and show it on gridview ? Someone pls help me out .. Thank u

Re: How to read data from excel sheet and show it on gridview ?
Najmul Hoda
10 Oct 2011 at 09:13 PM

Hi,

Please use the below code read data from excel and show in grid view

OleDbConnection sqlCon;
try
{
 string strConn = @"provider=Microsoft.Jet.OLEDB.4.0; data source=" + Server.MapPath("~/Upload/EBREADING.xls") + ";Extended Properties=Excel 8.0;";
 sqlCon = new OleDbConnection(strConn);
 if (sqlCon.State == ConnectionState.Open)
 {
    sqlCon.Close();
 }
 }
 catch
 {
    sqlCon = new  OleDbConnection(@"provider=MMicrosoft.ACE.OLEDB.12.0; data source=" + Server.MapPath("~/Upload/EBREADING.xls") + ";Extended Properties=Excel 12.0;");
     if (sqlCon.State == ConnectionState.Open)
     {
       sqlCon.Close();
     }
 }
 OleDbDataAdapter dataAdapter = new OleDbDataAdapter("select * from  [sheet1$] ", sqlCon);

 DataSet ds = new DataSet();
 if (sqlCon.State == ConnectionState.Closed)
 sqlCon.Open();
 dataAdapter.Fill(ds);

 GridView11.DataSource=ds;
 GridView.DataBind()

 

 

Hope this will help you.

Total Replies: 1
 
Featured Text Ad


Featured Ad