Solved

VB.Net --> DataSet to textfile!

Posted on 2006-10-19
5
1,101 Views
Last Modified: 2008-02-01
I have a dataset that I need to write to a text file out on my server.

The text file will not exist and will need to have the current datetime timestamp in the name.  So, essentially,  I pull data from sql and create a series of datasets.  I need to output the datasets to text files that look like the following.

dataset1_currentdatetime.txt
dataset2_currentdatetime.txt
dataset3_currentdatetime.txt

Any and all information is so greatly appreciated...

0
Comment
Question by:ucic
[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
  • 3
  • 2
5 Comments
 
LVL 17

Expert Comment

by:ZeonFlash
ID: 17767790
You can output the a dataset's contents in XML format like this:

Dim strm As New IO.StreamWriter("C:\dataset1_" & Now.ToString("MM-dd-yyyy_HHmmtt") & ".txt", False, System.Text.Encoding.Unicode)
ds.WriteXml(strm)
0
 

Author Comment

by:ucic
ID: 17767927
Im already doing this in xml and it is not a feasible solution...

The project requires that the files get output directly to pipe delimited text files...

dak
0
 
LVL 17

Accepted Solution

by:
ZeonFlash earned 500 total points
ID: 17768031
In that case:

Dim strRow As String
Dim i As Integer
Dim strm As New IO.StreamWriter("C:\dataset1_" & Now.ToString("MM-dd-yyyy_HHmmtt") & ".txt", False, System.Text.Encoding.Unicode)

For Each dt As DataTable In ds.Tables
      For Each dr As DataRow In dt.Rows
            strRow = Nothing
            For Each col As DataColumn In dt.Columns
                  strRow &= dr(col) & "|"
            Next
            strRow = strRow.Remove(strRow.Length - 1, 1)
            strm.WriteLine(strRow)
      Next
Next

strm.Close()
0
 

Author Comment

by:ucic
ID: 17768082
Seems to create the text file, however...it seems to be create a pipe & tab delimeter...
Any ideas?
0
 

Author Comment

by:ucic
ID: 17768377
Got it figured out...I had a char datatype...All fixed...You Rock!
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

751 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