1

I'm able to select an entire table from an Access database, into a CSV using the following code via VB.NET:

Dim AccessCommandCust As New OleDbCommand("SELECT * INTO [Text;DATABASE=C:\TEMP].[CUSTOMERS.csv] FROM Customers", AccessConn)

However, I don't need the entire table, just two columns -- Firstname and Lastname. The SQL is simple enough, but when I attempt this using the following code:

Dim AccessCommandCust As New OleDbCommand("SELECT FirstName, LastName INTO [Text;DATABASE=C:\TEMP].[CUSTOMERS.csv] FROM Customers", AccessConn)

It raises an exception:

Microsoft Jet database engine could not find the object 'CUSTOMERS.csv').

I'm trying to figure out where I'm going wrong.

2
  • If you find so many problems with SQL strings or syntax, you could also use an adapter to fill a DataSet. Then you can only select desired columns and finally store it into csv. That is prety fast and you can manage data.
    – Jaume
    Jan 5, 2016 at 10:16
  • That's where I am now. SQL on its own is fine, but this particular command doesn't seem to allow for anything other than selecting the entire table (*). Thank you for the reply!
    – Samskara
    Jan 5, 2016 at 14:14

1 Answer 1

1

The following syntax ended-up working for me:

Dim AccessCommandCust As New System.Data.OleDb.OleDbCommand("SELECT FirstName, LastName INTO [Text;HDR=YES;DATABASE=C:\Temp\].CUSTOMERS.csv FROM Customers", AccessConn)

The brackets [] around the filename itself, appear to be the issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.