======================================
"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
- 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()
~~~~
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
- "("SELECT * INTO
- [Text;HDR=No;DATABASE=e:\My Documents\TextFiles].[td.txt] FROM Table_3", AccessConn)"
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
- OleDbConnection AccessConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\PlaneBase\\pb_mil.mdb");
- AccessConn.Open();
- OleDbCommand AccessCommand = new OleDbCommand("SELECT * INTO [Text; HDR = No; DATABASE = c:\\PlaneBase\\].[MilTable.txt] FROM military", AccessConn);
- AccessCommand.ExecuteNonQuery();
- AccessConn.Close();
"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