Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 439
  • Last Modified:

Output dataset to a text file.

i need a routine to output a dataset to a textfile.

I appreciate.

Thanks.
0
mathieu_cupryk
Asked:
mathieu_cupryk
  • 5
  • 4
  • 2
1 Solution
 
TimCotteeCommented:
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
 
Chandan_GowdaCommented:
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
 
TimCotteeCommented:
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Chandan_GowdaCommented:
its just an alternate approach.....I agree writexml is the best approach.......I cannot post the same answer as yours......
0
 
mathieu_cuprykAuthor Commented:
this is in xml.

do u have a text.
0
 
TimCotteeCommented:
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
 
mathieu_cuprykAuthor Commented:
one file each guy is one line.
0
 
TimCotteeCommented:
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
 
mathieu_cuprykAuthor Commented:
this solution is the fully done and works 100%.
0
 
mathieu_cuprykAuthor Commented:
this solution is the fully done and works 100%.
0
 
mathieu_cuprykAuthor Commented:
i appreciate everyones colaboration.

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now