|
-
August 7th, 2009, 08:54 AM
#1
Export Microsoft Access Database to Text File
Hi, I'm using Visual Basic Express 2008 (VB.NEt). I've created a project which
connect to a Microsoft Access Database (OLEDB) & displays the records using textboxes in the windows app.
I need to add a button which exports the database to a fixed length text file. Does anyone know the code I would use to do this?
-
August 7th, 2009, 10:42 AM
#2
Re: Export Microsoft Access Database to Text File
There are several ways to do it.
One method would be to first create a string that contains the data for a given record by padding each field to the desired lenght and concantonating them together. Then use one of the file or streamwriter methods to write the string to the choosen file.
Here is a little sub routine from one of my old VS2003 projects which I use to write a line to a file as data is collected.
Code:
Private Sub FileWrite(ByVal fText As String)
Dim ofile As New System.IO.StreamWriter("\ToolCrib.txt", True)
ofile.WriteLine(ftext)
ofile.Close()
End Sub
-
August 7th, 2009, 11:00 AM
#3
Re: Export Microsoft Access Database to Text File
But I don't want it to create the file until the button is clicked. once the button is clicked I want it to take the data from the database & create the fixed length text file.
-
August 7th, 2009, 02:52 PM
#4
Re: Export Microsoft Access Database to Text File
Of course.. That was just an example of how to write a line to a file. To do what you want simply use a loop to write all the lines to the file before you close it. Everything you need to know about how to write the data to the file is there. I assume you already know how to get the data fromt he database.
-
August 7th, 2009, 02:56 PM
#5
Re: Export Microsoft Access Database to Text File
Bad assumption. I am just a beginner here. Which is why i'm asking for help with the code. I'm not sure where to begin or end.
-
August 7th, 2009, 04:01 PM
#6
Re: Export Microsoft Access Database to Text File
In the button's click event handler, open the connection to the database and using the Datareader read the data and the code in Post #2 shows how to to write it to the text file. It should be straight forward as long as you know how to connect to the access database and how to open a datareader for reading the data.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|