Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Write to TextFile(ASCII) using VB.NET

Posted on 2003-11-12
1
Medium Priority
?
1,177 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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

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…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

618 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