Write to TextFile(ASCII) using VB.NET

  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

Who is Participating?
adomsgConnect With a Mentor Commented:
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
                objwriter = File.CreateText(fileName)
                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
            Catch ex As Exception
                End Try

writeline() will write the data and move to next line
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.