473,426 Members | 1,758 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,426 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 7089
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
1
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

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.