Solved

Write to TextFile(ASCII) using VB.NET

Posted on 2003-11-12
1
1,144 Views
Last Modified: 2007-12-19
hi,
  i m new in VB.NET & now i need to using VB.NET to develop some Window Application which need to write the filed from database to textfile with the following criteria...


  - All fields are separated by a comma
  - Each record is terminated with a carriage return/line feed


which i think is a standard format of most people practice


can someone give me a clue on this issue, thanks



   
0
Comment
Question by:tayleeming
1 Comment
 
LVL 2

Accepted Solution

by:
adomsg earned 50 total points
ID: 9737807
Dim Conn As New OleDbConnection(Connect)
            Dim myselect As New OleDbCommand()
            myselect.Connection = Conn

Dim myreader As OleDbDataReader
            Dim fileName As String = MapPath("temp.txt")
            Dim objwriter As StreamWriter
            Try
                objwriter = File.CreateText(fileName)
                Conn.Open()
                myselect.CommandText = <select statement>
myreader = myselect.ExecuteReader()
                    While myreader.Read()
                        objwriter.Write(myreader.GetDecimal(0).ToString + ",")
                        objwriter.Write(myreader.GetValue(1) + ",")
                        objwriter.Write(myreader.GetString(2) + ",")
                        objwriter.Write(myreader.GetString(3) + ",")
                        objwriter.Write(myreader.GetString(4) + ",")
                        objwriter.Write(myreader.GetString(5) + ",")
                        objwriter.WriteLine(myreader.GetValue(6) + ",")
                    End While
                    myreader.Close()
                objwriter.Close()
            Catch ex As Exception
                End Try
            Conn.Close()

writeline() will write the data and move to next line
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

705 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now