Connecting Tech Pros Worldwide Forums | Help | Site Map

Exporting Data from DataSet to text file or xls file

Familiar Sight
 
Join Date: Apr 2008
Posts: 149
#1: Sep 25 '09
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!

ssnaik84's Avatar
Member
 
Join Date: Aug 2009
Location: Bengaluru, India
Posts: 124
#2: Sep 25 '09

re: Exporting Data from DataSet to text file or xls file


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");
Familiar Sight
 
Join Date: Apr 2008
Posts: 149
#3: Sep 25 '09

re: Exporting Data from DataSet to text file or xls file


Quote:

Originally Posted by ssnaik84 View Post

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");

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!
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,161
#4: Sep 25 '09

re: Exporting Data from DataSet to text file or xls file


Have you looked at the .WriteXML() function?
Familiar Sight
 
Join Date: Apr 2008
Posts: 149
#5: Sep 27 '09

re: Exporting Data from DataSet to text file or xls file


Quote:

Originally Posted by Plater View Post

Have you looked at the .WriteXML() function?

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!
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,161
#6: Sep 28 '09

re: Exporting Data from DataSet to text file or xls file


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?
Familiar Sight
 
Join Date: Apr 2008
Posts: 149
#7: Sep 29 '09

re: Exporting Data from DataSet to text file or xls file


Quote:

Originally Posted by Plater View Post

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?

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!
Newbie
 
Join Date: Sep 2009
Location: Pune
Posts: 8
#8: Sep 29 '09

re: Exporting Data from DataSet to text file or xls file


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

Tabla
Familiar Sight
 
Join Date: Apr 2008
Posts: 149
#9: Sep 29 '09

re: Exporting Data from DataSet to text file or xls file


Quote:

Originally Posted by tabla View Post

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

Tabla

Could you pls. elaborate more on what you want to say ..?

Thanks!
Newbie
 
Join Date: Sep 2009
Location: Pune
Posts: 8
#10: Sep 29 '09

re: Exporting Data from DataSet to text file or xls file


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
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,137
#11: Sep 29 '09

re: Exporting Data from DataSet to text file or xls file


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
Familiar Sight
 
Join Date: Apr 2008
Posts: 149
#12: Sep 30 '09

re: Exporting Data from DataSet to text file or xls file


Quote:

Originally Posted by Frinavale View Post

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

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!
Familiar Sight
 
Join Date: Apr 2008
Posts: 149
#13: Oct 7 '09

re: Exporting Data from DataSet to text file or xls file


Hi All,

Any inputs..?

Please reply!
Newbie
 
Join Date: Oct 2009
Posts: 1
#14: Oct 7 '09

re: Exporting Data from DataSet to text file or xls file


Hi all

Can u just anyone help me out in one project. i need to do a project in .net . the topic is displaying the student result.
1. Front End - .net
2.Back end - sql


please any response can mail to <email snipped>

kindly help as it is urgent
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,137
#15: Oct 7 '09

re: Exporting Data from DataSet to text file or xls file


Quote:

Originally Posted by sathya1990 View Post

Hi all

Can u just anyone help me out in one project. i need to do a project in .net . the topic is displaying the student result.
1. Front End - .net
2.Back end - sql


please any response can mail to <email snipped>

kindly help as it is urgent

Hi Sathya,

The experts here would be happy to give you a hand but you have to at least attempt the problem before asking for help. Once you have attempted the project, and you've run into a problem with a specific piece of code or concept then ask us for help by starting a new thread in the .net forum.

Cheers!

-Frinny
Familiar Sight
 
Join Date: Apr 2008
Posts: 149
#16: Oct 7 '09

re: Exporting Data from DataSet to text file or xls file


Quote:

Originally Posted by sathya1990 View Post

Hi all

Can u just anyone help me out in one project. i need to do a project in .net . the topic is displaying the student result.
1. Front End - .net
2.Back end - sql


please any response can mail to <email snipped>

kindly help as it is urgent

Hi,

I think you continued with the wrong thread..
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,161
#17: Oct 7 '09

re: Exporting Data from DataSet to text file or xls file


Quote:

Originally Posted by madankarmukta View Post

Hi All,

Any inputs..?

Please reply!

create/open file. Write contents. flush stream and close.
Not a complicated task?
Reply


Similar .NET Framework bytes