473,466 Members | 1,382 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to save DataSet into Excel files

Hi, I'm using OleDb to read an excel files and display the data in a datagrid (using dataset as data source), after modifying the data on datagird, how can I save the changes back into Excel files.

Thankz....

--
Message posted via http://www.dotnetmonster.com
Nov 16 '05 #1
3 15457
yaya,

There are a few ways that you can go about doing this. The most obvious
way I would think of doing this would be to use the OLE DB provider for
Excel and try to use an OleDbDataAdapter, calling Update.

If you are using a version of Excel that supports XML, then you can just
take the dataset that the grid is bound to and then save the XML contents.

If that doesn't work, then you could take the data set, and write out to
a CSV file (cycling through the rows and columns). If you want the native
Excel format, then you will have to access Excel through automation and
populate the sheet yourself.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"yaya via DotNetMonster.com" <fo***@DotNetMonster.com> wrote in message
news:0b******************************@DotNetMonste r.com...
Hi, I'm using OleDb to read an excel files and display the data in a
datagrid (using dataset as data source), after modifying the data on
datagird, how can I save the changes back into Excel files.

Thankz....

--
Message posted via http://www.dotnetmonster.com

Nov 16 '05 #2
Yes, just as you mentioned, I'm trying to call OleDbDataAdapter's Update but I get this error
---------------------------------------------------------------------
System.InvalidOperationException: Update unable to find TableMapping['Table'] or DataTable 'Table'.
at System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String srcTable)
at System.Data.Common.DbDataAdapter.Update(DataSet dataSet)
at TPApplication.frm_main.ReadExcelFile(String fileName) in c:\...
---------------------------------------------------------------------

Here is my code to read the data from Excel
---------------------------------------------------------------------using System.Data.OleDb;

string strCon = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = c:\\Test.xls;Extended Properties=Excel 8.0";

OleDbConnection myConn = new OleDbConnection(strCon);
string strCom = " SELECT * FROM [Sheet1$] ";
myConn.Open();

OleDbDataAdapter myCommand = new OleDbDataAdapter(strCom , myConn);
DataSet inputDataSet = new DataSet();
myCommand.Fill (inputDataSet, "[Sheet1$]");
myConn.Close();

dtg_input.DataMember= "[Sheet1$]";
dtg_input.DataSource = inputDataSet;

// Some changes made in the datagrid, and I wana save the changes

**************Error*********************
myCommand.Update(inputDataSet);
****************************************

Thankz again...

--
Message posted via http://www.dotnetmonster.com
Nov 16 '05 #3
Is that any other way to save the Dataset into Excel files?
Thankz...

--
Message posted via http://www.dotnetmonster.com
Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Alex Shirley | last post by:
Hi I'm still banging my head on how to import an Excel XML spreadsheet into a dataset. The code will work for standard XML files, but not XML files made with Excel (I get 'Specified cast is not...
1
by: tkaleb | last post by:
I have to create output file in a text, MS Access, MS Excel and .dbf format from C# Win/ADO.NET application. Data are collected in DataSet and there is no problem to make text file. However, I have...
4
by: Jae | last post by:
I'm writing a web application that exports and imports excel files. The application gets a list of users and their info and displays it in a datagrid .The user then selects to save the file as a...
2
by: PB | last post by:
I need to enable users to download data in either an Excel file or an Access database (MDB file). The data they need exists in a SQL Server database: the XLS or MDB file does not actually exist...
4
by: washoetech | last post by:
Hello, I am working on a project where I need to be able to grab the data from an Excel spreadsheet and create a new table in my database based on the columns in the spreadsheet. After the...
6
by: Michael Groeger | last post by:
Hi, I have an aspx page which generates an excel document and transfers it to the browser as attachment. Normally, once the document is transferred the open save dialog prompts to open or save...
2
by: awu | last post by:
All: I have a query that has 5 fields and around 15500 records. I need to save it to a excel file that has two sheets. First sheet saves all the 15500 records. Second sheet saves around 7500...
3
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, I have a question for you. I have a .csv file which has many lines of data. Each line has many data fields which are delimited by ",". Now I need to extract part of data from this...
3
by: evenlater | last post by:
I have an Access application on a terminal server. Sometimes my users need to export reports to pdf, rtf or xls files and save them to their own client device hard drives. They can do that right...
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.