473,586 Members | 2,495 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

5 New Member
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 programmaticall y 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.Ol eDb.OleDbExcept ion' occurred in System.Data.dll

Additional information: Could not find file 'c:\users\micha el\documents\vi sual studio 2015\Projects\A ccessTest1\Acce ssTest1\bin\Deb ug\Text'."
Why is it even looking for a file called "Text" ?
Many thanks.

Michael
May 15 '16 #1
1 3934
MichaelHooker
5 New Member
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
6342
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 database using unicode compression field (for ancient language). I would like to export this table into MySQL o Postgres, but it's
4
3160
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 database using unicode compression field (for ancient language). I would like to export this table into MySQL o Postgres, but it's
7
5135
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 probleme? To export my tables i use folowing code: StTotaal = stLocatieName & "\Archief\" & Year(Date) & Month(Date) & Day(Date) & "_Gegevens.xls" ...
3
7548
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 DoCmd.OpenQuery "qry_delete FCL" DoCmd.OpenQuery "qry_temp FCL"
1
5953
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 pipe delimited text file. Appreciate any help!!!
1
3079
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 requirement is to export a table in MS Access to MySQL and I've to get over it using the VBA script from within MS Access. Could you please point me/advice me...
0
2105
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 should start from column B in excel. The column A of the excel file should have heading "Extract Policy" followed by checkboxes so that the user...
9
1697
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 of columns and the column names were always the same for a given table. I was using then short exporting modules (example of code below) that I...
5
2684
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 information from my Quote log table in Access to update a different Excel spreadsheet. I created an Update Query using the Access table as my source...
3
2193
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 same excel workbook.I also want to be prompted to search and pick the excel file that the tables are going to be exported as opposed to specifying the...
0
7841
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8204
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7965
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...
0
8220
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...
0
6617
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...
0
5392
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...
0
3869
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1184
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...

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.