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

Write to TextFile(ASCII) using VB.NET

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
tayleeming
Asked:
tayleeming
1 Solution
 
adomsgCommented:
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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