?
Solved

Write to TextFile(ASCII) using VB.NET

Posted on 2003-11-12
1
Medium Priority
?
1,161 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
[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
1 Comment
 
LVL 2

Accepted Solution

by:
adomsg earned 200 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

741 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