Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VB.Net --> DataSet to textfile!

Posted on 2006-10-19
5
Medium Priority
?
1,121 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
  • 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 2000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

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 …
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

886 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