Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Output dataset to a text file.

Posted on 2008-06-23
14
Medium Priority
?
438 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
14 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 2000 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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
 
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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

636 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