469,341 Members | 6,659 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Exporting Data from DataSet to text file or xls file

308 256MB
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
13 4087
ssnaik84
149 100+
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
madankarmukta
308 256MB
@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
7,872 Expert 4TB
Have you looked at the .WriteXML() function?
Sep 25 '09 #4
madankarmukta
308 256MB
@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
7,872 Expert 4TB
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
madankarmukta
308 256MB
@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
tabla
8
Hi,
Have u tried it with UTL package.check the same it is very fast.

Tabla
Sep 29 '09 #8
madankarmukta
308 256MB
@tabla
Could you pls. elaborate more on what you want to say ..?

Thanks!
Sep 29 '09 #9
tabla
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
9,735 Expert Mod 8TB
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
madankarmukta
308 256MB
@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
madankarmukta
308 256MB
Hi All,

Any inputs..?

Please reply!
Oct 7 '09 #13
Plater
7,872 Expert 4TB
@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.

Similar topics

3 posts views Thread by Chris | last post: by
2 posts views Thread by Mike P | last post: by
2 posts views Thread by brian | last post: by
3 posts views Thread by David P. Donahue | last post: by
reply views Thread by Mike Collins | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by haryvincent176 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.