473,387 Members | 1,596 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 8136
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Random Person | last post by:
Does anyone know how to use VBA to relink tables between two MS Access databases? We have two databases, one with VBA code and the other with data tables. The tables are referenced by linked...
3
by: ET | last post by:
I don't know whats the problem, but after I added functions to first verify, then relink linked tables if not found, now I can't convert that database to MDE format. I can split the database, but...
1
by: JH | last post by:
I have a comma delimited file and I want to export it to an MS access table already designed with appropriate field names. How do I do this programmatically using VB.NET or C#? Thanks for any...
3
by: dale zhang | last post by:
Hi, I am trying to read an image from MS Access DB based on the following article: http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp The article author is using PictureBox for windows...
4
by: dale zhang | last post by:
Hi, I am trying to save and read an image from MS Access DB based on the following article: http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp Right now, I saved images without any...
52
by: Neil | last post by:
We are running an Access 2000 MDB with a SQL 7 back end. Our network guy is upgrading to Windows Server 2003 and wants to upgrade Office and SQL Server at the same time. We're moving to SQL Server...
2
by: egoldthwait | last post by:
I need to convert a 17mb access 2000 db to Oracle and house it in a Citrix farm. The issue: we have never converted an Access Db to Oracle but can probably use Oracle's Workbench to assist with...
1
by: Parasyke | last post by:
Thanks in advance. I'm new to XML. I need to convert an existing Access table into XML which will allow me on a form to read the table into XML, edit, then reconvert it back to the Access table. I...
2
budigila
by: budigila | last post by:
Hiya peeps, Okies, I have been trying to work this out for a while now to no avail... I am a beginner to this whole coding thing but have made great strides in my project. Basically what I am...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.