469,946 Members | 1,805 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,946 developers. It's quick & easy.

Import Excel file to Gridview

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
1 6834
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.

Similar topics

reply views Thread by Ned Balzer | last post: by
3 posts views Thread by =?Utf-8?B?bWFuaWthMDI=?= | last post: by
3 posts views Thread by Mel | last post: by
4 posts views Thread by orked | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.