Solved

Output dataset to a text file.

Posted on 2008-06-23
14
429 Views
Last Modified: 2013-12-16
i need a routine to output a dataset to a textfile.

I appreciate.

Thanks.
0
Comment
Question by:mathieu_cupryk
  • 5
  • 4
  • 2
14 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 500 total points
ID: 21845242
Hello mathieu_cupryk,

Depends what sort of text file you want. The simplest is to use the .WriteXML("MyFilename.xml") method of the dataset, the advantage being that you can use the corresponding .ReadXML method to read the contents back into a dataset at a later stage.

Regards,

TimCottee
0
 
LVL 7

Expert Comment

by:Chandan_Gowda
ID: 21845294
try the attached code
    private void WriteToTextFile()

    {

        DataSet ds = new DataSet();

        string strDSValue = "";

        //ds =data returned by u r query

        if (ds!=null)

         strDSValue = ds.GetXml(); ;

        System.IO.StreamWriter objStreamWriter = new System.IO.StreamWriter("test.txt");

        objStreamWriter.WriteLine(strDSValue);

        objStreamWriter.Close();

    }

Open in new window

0
 
LVL 43

Expert Comment

by:TimCottee
ID: 21845305
Chandan_Gowda,

Don't see why you would use that over the WriteXML method as it includes an overload to specify the filename (which can be anything you want).

TimCottee
0
 
LVL 7

Expert Comment

by:Chandan_Gowda
ID: 21845333
its just an alternate approach.....I agree writexml is the best approach.......I cannot post the same answer as yours......
0
 

Author Comment

by:mathieu_cupryk
ID: 21845911
this is in xml.

do u have a text.
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 43

Expert Comment

by:TimCottee
ID: 21845948
mathieu_cupryk,

That is why I ask, of course XML is simply text when you get down to it. I assume that you mean you would prefer something along the lines of CSV rather than XML. What happens then if you have multiple tables contained within your dataset? How would you like to output that - as seperate files or somehow as a seperate section within a single file? What do you want to do with the text file once you have output it?

All of these things are relevant and would help to decide what kind of approach to take in this situation.

TimCottee
0
 

Author Comment

by:mathieu_cupryk
ID: 21845965
one file each guy is one line.
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 21846416
mathieu_cupryk,

That just outputs it as XML anyway, I don't understand why (and Chandan even admits that it isn't) this is the best solution. If you want a filename ending in .txt then call it that using:

.WriteXML ("MyFilename.TXT")!

TimCottee
0
 

Author Comment

by:mathieu_cupryk
ID: 21891298
this solution is the fully done and works 100%.
0
 

Author Closing Comment

by:mathieu_cupryk
ID: 31469695
this solution is the fully done and works 100%.
0
 

Author Comment

by:mathieu_cupryk
ID: 21892699
i appreciate everyones colaboration.

0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now