473,750 Members | 2,182 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 programmaticall y using VB.NET or C#?

Thanks for any help in advance.
Raju

Sep 2 '06 #1
4 8192
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("F ileName.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("FIELD 1") & "," & myReader("FIELD 2") & ","
& myReader("FIELD 2")......

' Write record in file.
sw.WriteLine(st rRecord )
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 programmaticall y 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.Ole Db.OleDbConnect ion("Provider=M icrosoft.Jet.OL EDB.4.0;"
& _
"Data Source=e:\My Documents\db1.m db")

AccessConn.Open ()

Dim AccessCommand As New System.Data.Ole Db.OleDbCommand ("SELECT * INTO
[Text;HDR=No;DAT ABASE=e:\My Documents\TextF iles].[td.txt] FROM Table_3", AccessConn)

AccessCommand.E xecuteNonQuery( )
AccessConn.Clos e()
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 programmaticall y 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.Ole Db.OleDbConnect ion("Provider=M icrosoft.Jet.OL EDB.4.0;"
& _
"Data Source=e:\My Documents\db1.m db")

AccessConn.Open ()

Dim AccessCommand As New System.Data.Ole Db.OleDbCommand ("SELECT *INTO
[Text;HDR=No;DAT ABASE=e:\My Documents\TextF iles].[td.txt] FROM Table_3", AccessConn)

AccessCommand.E xecuteNonQuery( )
AccessConn.Clos e()
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;DAT ABASE=e:\My Documents\TextF iles].[td.txt] FROM Table_3
to generate the export in a TAB delimited format?

Thanks in advance.

aa*********@gma il.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 programmaticall y 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.Ole Db.OleDbConnect ion("Provider=M icrosoft.Jet.OL EDB.4.0;"
& _
"Data Source=e:\My Documents\db1.m db")

AccessConn.Open ()

Dim AccessCommand As New System.Data.Ole Db.OleDbCommand ("SELECT* INTO
[Text;HDR=No;DAT ABASE=e:\My Documents\TextF iles].[td.txt] FROM Table_3", AccessConn)

AccessCommand.E xecuteNonQuery( )
AccessConn.Clos e()


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
24035
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 tables in the database where the code resides. If we move the database with the data tables to a new directory, the links are no longer valid. I tried to update the links by changing the Connect property and refreshing: Set td = db.TableDefs(0)...
3
2704
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 can't convert part of the database with forms, reports, queries to MDE format. Can somebody advice on this? References, in the order, from the top:
1
4482
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 help in advance.
3
3637
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 application, while I am doing for web. I can only find Image from web forms control and HTML control. This may be the root cause of my problem. For read button, I converted his VB to the C#. But the compiler complains:
4
3302
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 errors. After reading the ole object from db, I saved it to C: as file1.bmp and displayed on the web. But it can not be displayed. After I manually sent the file to wordpad, it shows
52
9980
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 2005, and, since he already has licenses for Office Pro 2002, he wants to upgrade to that. I've been saying that we need to upgrade to Access 2003, not 2002, even if Office is kept at 2002. We are also looking to do a fair amount of...
2
4239
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 this. Also - the citrix folks do not want us to keep the FE in Access as the queries and other activities consume a lot of power. The users will be in 3 different offices across the globe all accessing the 1 Oracle DB in Citrix. Does anyone have...
1
1707
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 have successfully added the Northwind database to my data sources in Visual Studio 2003 (Standard Edition). I also have the following code which reads from an EXISTING XML file not related to the Access file. How could I alter it to pull from...
2
5188
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 trying to do is to convert an .xml using a .xsl to and using a java script to output it into a readable format within excel. I have been able to successfully use a javascript to combine my .xml and .xsl but cannot figure out how to have it output to...
0
9394
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9338
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9256
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8260
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6803
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6080
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4712
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4885
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2223
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.