468,733 Members | 1,290 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,733 developers. It's quick & easy.

Convert Access Table to Text File using VB

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

Sep 2 '06 #1
4 7683
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

Sep 2 '06 #2
On 1 Sep 2006 23:16:51 -0700, ra******@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=Micros oft.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)
Sep 5 '06 #3
wow. I am blown away.

Does that require Access to be on the machine? I've always been under
the assumption that the brackets were only available from within
MSACCESS.exe

-Aaron
Paul Clement wrote:
On 1 Sep 2006 23:16:51 -0700, ra******@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=Micros oft.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)
Sep 5 '06 #4
I'm blown away as well, that's a pretty cool solution.

The one thing I feel like a complete idiot asking is the default file
export format is always CSV delimited, and I'd like my export to be a
TAB delimited text file. I've tried a zillion keywords to do this, all
with no luck. No help from google yet.

Could someone please let me know what I need to change in

SELECT * INTO
[Text;HDR=No;DATABASE=e:\My Documents\TextFiles].[td.txt] FROM Table_3
to generate the export in a TAB delimited format?

Thanks in advance.

aa*********@gmail.com wrote:
wow. I am blown away.

Does that require Access to be on the machine? I've always been under
the assumption that the brackets were only available from within
MSACCESS.exe

-Aaron
Paul Clement wrote:
On 1 Sep 2006 23:16:51 -0700, ra******@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=Micros oft.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)
Sep 15 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Random Person | last post: by
52 posts views Thread by Neil | last post: by
2 posts views Thread by egoldthwait | last post: by
1 post views Thread by Parasyke | last post: by
1 post views Thread by CARIGAR | last post: by
xarzu
2 posts views Thread by xarzu | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.