• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1124
  • Last Modified:

VB.Net --> DataSet to textfile!

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
ucic
Asked:
ucic
  • 3
  • 2
1 Solution
 
ZeonFlashCommented:
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
 
ucicAuthor Commented:
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
 
ZeonFlashCommented:
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
 
ucicAuthor Commented:
Seems to create the text file, however...it seems to be create a pipe & tab delimeter...
Any ideas?
0
 
ucicAuthor Commented:
Got it figured out...I had a char datatype...All fixed...You Rock!
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

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