473,396 Members | 2,115 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 7085
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

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

Similar topics

3
by: deko | last post by:
I've been trying to use the Access Import Wizard to expedite importing data into my mdb. The nice thing about the wizard is that I can import from different file formats - txt, xls, even Outlook -...
2
by: Siu | last post by:
Hi, I use the following code to export and import a file Excel from resp. into a Web page with the following code: //EXPORT Response.Clear(); Response.Buffer = true; Response.ContentType =...
0
by: Ned Balzer | last post by:
I have a puzzling problem. I am using some code I found in another thread here to output the results of a gridview to excel. Here is the subroutine: Sub SendToExcel(ByVal Source As Object,...
3
by: =?Utf-8?B?bWFuaWthMDI=?= | last post by:
Hi, I have a GridView control in page called eventslisting which is inheriting from a MasterPage. The normal code to export to GridView does not work and gives me an error - "Control of type...
1
by: edwinparker | last post by:
Hi, I'm trying to convert a gridview to an excel report and have one small hang up. So far I've been able to create my gridview and export it to excel ok, but in my gridview I have an image. The...
8
by: shenkel55 | last post by:
I'm using Access and Excel 2003. Using either the import wizard or code, I have the same problem. This problem only happens with Excel files automatically generated by Corp IT. If I try to do an...
1
by: Yordan Georgiev | last post by:
I have a search form using master page , which is dynamically generated from the column names of the database - when the users have a search result it should be exported to Excel by clicking the...
3
by: Mel | last post by:
How do I open an Excel file as a read only document? It would be okay if it opened in the browser window but I don't want the user to save any changes and stomp over my original file on the...
4
by: orked | last post by:
i want to import excel file to gridview but there was error(Failed to map this path "/xmltest.xml") and i couldn't handle it my code: public void fillGrid() { DataSet ds = new...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.