By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,158 Members | 917 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,158 IT Pros & Developers. It's quick & easy.

Import Excel file to Gridview

P: 49
i tried to import excel file into gridview but the code made this exception (Failed to map this path''xmlTest.xml") i don't know why
my code:
Expand|Select|Wrap|Line Numbers
  1. public void fillGrid()
  2.     {
  3.         DataSet ds = new DataSet();
  4.         ds.ReadXml(Server.MapPath("../xmlTest.xml"));
  5.         GridView1.DataSource = ds;
  6.         GridView1.DataBind();
  7.     }
  8.     protected void Page_Load(object sender, EventArgs e)
  9.     {
  10.         if (!IsPostBack)
  11.         {
  12.             fillGrid();
  13.         }
  14.     }
  15.  
  16.     protected void btImport_Click(object sender, EventArgs e)
  17.     {
  18.         string conn = ("Provider=Microsoft.Jet.OLEDB.4.0;" + ("Data Source=C:\\WebSqlEditor\\test.xls;" + "Extended Properties=Excel 8.0;"));  
  19.         string SSQL = "SELECT name , dept, salary  from [sheet1$]";
  20.         OleDbDataAdapter oleDA = new OleDbDataAdapter(SSQL, conn); 
  21.         DataSet ds = new DataSet();
  22.         oleDA.TableMappings.Add("Table","ExcelTest"); 
  23.         oleDA.Fill(ds);
  24.         GridView1.DataSource = ds.Tables[0].DefaultView; 
  25.         GridView1.DataBind();
  26.     }
what i can do?
thanks
Mar 18 '09 #1
Share this Question
Share on Google+
1 Reply


P: 3
I suggest to use a*c# excel component Spire.XLS, I use it long time, quit good.
It*supports importing/exporting to XLS, XLSX, CSV and HTML files.
May help to you.
Aug 24 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.