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

Exporting Data from DataSet to text file or xls file

100+
P: 293
Hi all,

Is there any way by which I can export the data from the dataset table to the text file or xls file ?

Currently I implemented this by itterating through each row of the table and writting the data to file.I want to avoid iteration.It occured to me bcoz skipping iteration will improve the performance.

Please Help..

Thanks!
Sep 25 '09 #1
Share this Question
Share on Google+
13 Replies


ssnaik84
100+
P: 149
Do you want to save .xls file on disk or just to create-n-send through browser on-the-fly?
in second case, you just need to set page header...

Expand|Select|Wrap|Line Numbers
  1. HttpContext.Current.Response.ContentType = "text/csv";
  2. HttpContext.Current.Response.AddHeader("Pragma", "public");
Sep 25 '09 #2

100+
P: 293
@ssnaik84
Hi ,

Thanks for your reply.

But I want to export/copy data from dataset table to the file.The File I want to save it on local disk.

Please provide input.

Thanks!
Sep 25 '09 #3

Plater
Expert 5K+
P: 7,872
Have you looked at the .WriteXML() function?
Sep 25 '09 #4

100+
P: 293
@Plater
Hi,

Thanks for the reply.

per my understanding .. writeXml function is used to get the xml equivalent of the table's data which is not my goal. Suppose the dataset table contains the data as -

================
Column1 Column2
================
Value11 Value22
--------------------------------
Value12 Value21
--------------------------------
I want it should get write to the text file as it is and not it's xml format.

If I m wrong pls. correct me.

Thanks again!
Sep 27 '09 #5

Plater
Expert 5K+
P: 7,872
Well an XML file would be able to be read by Excel.
But for your request, you would need to format the data in a text string yourself. Looping through the data.
You could check to see if someone has already created a function for doing that?
Sep 28 '09 #6

100+
P: 293
@Plater
Hi,

Thanks for the reply.

As I stated earlier I implemented the same way as you described here.But to avoid the "looping through data" I want to have some direct way by which the data can directly exported to text file.

Though the code was working smoothly previously, it may lead to degrade the peformance;because my table will now hold the records at the count of a lacs or two.

Please provide inputs if you have any.

Thanks again!
Sep 29 '09 #7

P: 8
Hi,
Have u tried it with UTL package.check the same it is very fast.

Tabla
Sep 29 '09 #8

100+
P: 293
@tabla
Could you pls. elaborate more on what you want to say ..?

Thanks!
Sep 29 '09 #9

P: 8
Hi,
There is one package UTL_FILE in oracle which read/write/append the data into existing or New .txt or .xls or .csv file.

First have all the data which u want to write in file into cursor.
Then open a file in UTL directory (take help of dba to know the path).
Using UTL_FLIE.PUT_LINE procedure you can write a data in to FILE.
After reading all records from cursor close the open file.

Tabla
Sep 29 '09 #10

Frinavale
Expert Mod 5K+
P: 9,731
In case you're not using an Oracle Database....

It is probably a good idea if you research XML Serialization. The MSDN Library is a great place to start your research. For example it has an Introduction to XML Serialization article that states that you can use a XmlSerializer to serailize DataSet objects as XML.


Happy Coding
-Frinny
Sep 29 '09 #11

100+
P: 293
@Frinavale
Hi,

Thanks for your reply.

Per my understading Xmlserialization won't be useful. I don't want to transfer/post the object to and fro network/machines.I just want to get the data from the table to the text file as it is.Please provide input if you have any.

Thanks!
Sep 30 '09 #12

100+
P: 293
Hi All,

Any inputs..?

Please reply!
Oct 7 '09 #13

Plater
Expert 5K+
P: 7,872
@madankarmukta
create/open file. Write contents. flush stream and close.
Not a complicated task?
Oct 7 '09 #14

Post your reply

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