473,320 Members | 2,133 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,320 software developers and data experts.

Use SELECT INTO in C# to export Access table to csv file

At this topic "https://bytes.com/topic/visual-basic-net/answers/530817-convert-access-table-text-file-using-vb" is the following Q&A:
======================================
"I 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:

Expand|Select|Wrap|Line Numbers
  1. Dim AccessConn As New System.Data.OleDb.OleDbConnection("Provider=Micros oft.Jet.OLEDB.4.0;"
  2.  & _
  3.  "Data Source=e:\My Documents\db1.mdb")
  4.  
  5.  AccessConn.Open()
  6.  
  7.  Dim AccessCommand As New System.Data.OleDb.OleDbCommand("SELECT * INTO
  8.  [Text;HDR=No;DATABASE=e:\My Documents\TextFiles].[td.txt] FROM Table_3", AccessConn)
  9.  
  10.  AccessCommand.ExecuteNonQuery()
  11.  AccessConn.Close()
Paul

~~~~
Microsoft MVP (Visual Basic)
=================================================

Now I am trying to do the same in C#, but I cannot work out what the line
Expand|Select|Wrap|Line Numbers
  1. "("SELECT * INTO
  2.  [Text;HDR=No;DATABASE=e:\My Documents\TextFiles].[td.txt] FROM Table_3", AccessConn)" 
is supposed to do in order to make it work in my application. I'm guessing as follows:
Text = output format ?
HDR=NO means no header line ?
DATABASE = the path to the output file ?
.[td.txt] = the name of output file ?
Table_3 = the name of the Access table in the mdb file ?

Is there anything I need to change in its formatting to make it work in C#? The code I am trying is this:
Expand|Select|Wrap|Line Numbers
  1. OleDbConnection AccessConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\PlaneBase\\pb_mil.mdb");
  2. AccessConn.Open();
  3. OleDbCommand AccessCommand = new OleDbCommand("SELECT * INTO [Text; HDR = No; DATABASE = c:\\PlaneBase\\].[MilTable.txt] FROM military", AccessConn);
  4. AccessCommand.ExecuteNonQuery();
  5. AccessConn.Close();
  6.  
and the error I am getting is this:
"An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll

Additional information: Could not find file 'c:\users\michael\documents\visual studio 2015\Projects\AccessTest1\AccessTest1\bin\Debug\Te xt'."
Why is it even looking for a file called "Text" ?
Many thanks.

Michael
May 15 '16 #1
1 3898
I would love to have used this SELECT INTO construction, but in the absence of any useful information that I could find on the net, and with no response here, I tried a less elegant program solution - retrieving lines of data and saving them one at a time to a text file. It takes ages but it works.

Does anyone know where I can find further info on this use of SELECT INTO to create a text file, as promoted by Microsoft MVP Paul, who is (or was?) a member of this community ?

Thanks

Michael
May 21 '16 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: JJ | last post by:
Hi, usually, I'm not using MS servers, but I have a big problem with a Access table. I should create a web application for a Historical Dipartment. They have create a populated a Access...
4
by: JJ | last post by:
Hi, usually, I'm not using MS servers, but I have a big problem with a Access table. I should create a web application for a Historical Dipartment. They have created a populated a Access...
7
by: Keon | last post by:
Hoi, I'm using a database with alot of records in 1 table (more than 3000). If i want to export this table to excel i only get it till record 2385. Do someone know how i can solve this...
3
by: bwhite | last post by:
I have a temp table with one row of data that I need to export into Excel. I created the export to create the xls file as follows ... Dim FileName FileName = !! DoCmd.SetWarnings False...
1
by: Stella | last post by:
Help!!! Am extremely new to VBA. Want to set up code behind a button that will prompt the user for a table name(source of data) and file name(end result of export) and then export the data into a...
1
by: Harnish | last post by:
Hey All! This is Harnish. I am extremely new to both VBA and this forum! Could anyone please point me to some sample code (VB) to export a table in MS Access to MySQL. Essentially my...
0
by: JFKJr | last post by:
Hello everyone! I am trying to export Access table data into Excel file in such a way that the table field names should be in the first line of each column in excel file followed by field data, and...
9
by: mabrynda | last post by:
Good morning everybody, I have an ACCESS project, in which I was expotring some tables as TXT files to be used as input for some MATLAB code. Until now, these tables were "static" - means the number...
5
by: Daryl Austin | last post by:
I successfully linked an Excel file into my Access database and using an Update query pull in information to my Quote log table. That works fine. Now I am trying to go the other direction, and use...
3
elak6
by: elak6 | last post by:
I am creating a form which will act as a dashboard for a variety of other functions I am currently having problems in one aspect I want to export mutiple tables to different worksheets in the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.