Home All Groups Group Topic Archive Search About

Convert Access Table to Text File using VB

Author
2 Sep 2006 6:16 AM
raju5725
have a MS access table and I want to export it to comma delimited
text file. How do I do this programmatically using VB.NET or C#?

Thanks for any help in advance.


Raju

Author
2 Sep 2006 1:46 PM
Pragati Palewar
Hi,

For exporting Access table data, you need to read the records in
DataReader and then write these records in .CSV file one by one....

You need to follow these steps:

1. Open the file for writing (in append mode) with file stream writer:
Dim sw As New StreamWriter("FileName.csv", True)

2. Read table in DataReader.

3. Loop throught the data reader, Read record in string variable, Write
in File.

Dim strRecord as string

Do While myReader.Read()
   ' Use ',' (comma) as seperator when you are writing field values in
file.
   strRecord = myReader("FIELD1")  & ","  &  myReader("FIELD2")  & ","
& myReader("FIELD2")......

   ' Write record in file.
   sw.WriteLine(strRecord )
Loop

I don't know if there is some other way to do this.

Regards,

Pragati Palewar

Palewar Techno Solutions
Windows & Windows Mobile Software Development
Nagpur, India

http://www.palewar.com
Author
5 Sep 2006 7:11 PM
Paul Clement
On 1 Sep 2006 23:16:51 -0700, raju5***@gmail.com wrote:

¤  have a MS access table and I want to export it to comma delimited
¤ text file. How do I do this programmatically using VB.NET or C#?
¤
¤ Thanks for any help in advance.

You can do this rather easily with ADO.NET and SQL:

        Dim AccessConn As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;"
& _
                                                            "Data Source=e:\My Documents\db1.mdb")

        AccessConn.Open()

        Dim AccessCommand As New System.Data.OleDb.OleDbCommand("SELECT * INTO
[Text;HDR=No;DATABASE=e:\My Documents\TextFiles].[td.txt] FROM Table_3", AccessConn)

        AccessCommand.ExecuteNonQuery()
        AccessConn.Close()


Paul
~~~~
Microsoft MVP (Visual Basic)
Author
12 Sep 2006 9:44 AM
sugu bala
*** Sent via Developersdex http://www.developersdex.com ***