By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,492 Members | 1,289 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,492 IT Pros & Developers. It's quick & easy.

Convert Access Table to Text File using VB

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.