Question : .CSV to Database with ODBC connection.

I am trying to create a ODBC connection to a CSV file with the following code:

string CSVFolderPath = "c:\\CSAMS\\baudtest.csv";
string ConnectionString = "Driver={Microsoft Text Driver (*.txt;*.csv)};Dbq=" + CSVFolderPath.Trim() + ";Extensions=asc,csv,tab,txt" + ";Persist Security Info=False";
OdbcConnection connection = new OdbcConnection(ConnectionString);
connection.Open();

The last line run time error's with the following error message

ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified.

The Value of the connection string is:
"Driver={Microsoft Text Driver (*.txt;*.csv)};Dbq=c:\\CSAMS\\baudtest.csv;Extensions=asc,csv,tab,txt;Persist Security Info=False"

and the CSV comma delimeted text file is located in c:\CSAMS\baudtest.csv so there is no problem with the path.  I have used it successfulle in VS 2003.  Is this maybe a 2005 thing?

Answer : .CSV to Database with ODBC connection.

You ll have to use a different driver to connect to csv file.

This is new command :

select * from OpenRowset('MSDASQL','Driver={Microsoft Text Driver (*.txt; *.csv)}; DefaultDir=C:\Temp;Extended properties=''ColNameHeader=True;Format=CSVDelimited;''','select * from Test.csv')

If you want more formating you ll need to use a schema.ini file

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/odbcjetschema_ini_file.asp

 
Random Solutions  
  •  access 2007 frontend sql server 2008
  •  Dropdowns in grid view 'edit item template' not working
  •  How do you import outlook express 6 messages into Windows Live Mail and have them in the proper folders?
  •  Cannot use remote executables after I upgraded to R2
  •  Mixed tooltips using AddTool (GetDlgItem (IDC_THIS), IDC_THIS) and AddTool (this, LPSTR_TEXTCALLBACK) how to.
  •  VPN client (Check point Secure client) not able to browse to any website on the machine once connected to the VPN.
  •  How do I remove special characters in a query?
  •  Expert Notify Thread - For Experts only (those answering questions in the MS Access Zone).
  •  DNS root hints not working Windows 2008
  •  can i use right([ClientName] to get the last part of a string in a Microsoft Access query if i don't know how long the last part is?
  •  
    programming4us programming4us