Solved

VB.Net --> DataSet to textfile!

Posted on 2006-10-19
5
1,104 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

Technology Partners: 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!

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

615 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