Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
This is driving me crazy:

I want to connet a CSV in C# when I press a button and the string connection reports error when the event happens , no path found, I don't know why. I google it but still having troubles. I try with next formats and they don't works:

a)

C#
string PATH = "C:\\Users\\xxx\\Documents\\Visual Studio 2013\\Projects\\tt\\tt\\Data\\";
string sConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + PATH + ";Extended Properties=\"text;HDR=yes;FMT=delimited\";";




b)

string sConnection =    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= C:\\Users\xxx\\Documents\\Visual Studio 2013\\Projects\\xx\\xx\\Data\\employees.csv;Extended Properties=\"text;HDR=YES;FMT=Delimited\"";


c)

C#
string PATH = "C:\\Users\xxx\\Documents\\Visual Studio 2013\\Projects\\xx\\xx\\Data\\employees.csv;";
            string sConnection = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=+PATH+;Extended Properties="Excel 12.0;HDR=YES";"



where is my mistake or what am i missing?
Posted
Updated 7-Sep-14 20:35pm
v3
Comments
pradiprenushe 5-Sep-14 22:57pm    
Remove filename from path
Kinna-10626331 8-Sep-14 2:34am    
string PATH = "C:\\Users\\xxx\\Documents\\Visual Studio 2013\\Projects\\tt\\tt\\Data\\";
string sConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + PATH + ";Extended Properties=\"text;HDR=yes;FMT=delimited\";";


it still not working
Richard MacCutchan 8-Sep-14 4:02am    
Your format specification is incorrect, it uses parentheses not quotes, and should be:
FMT=Delimited(;)

You should only pass the directory name when trying to read .csv files. See Using OleDb to Import Text Files (tab, CSV, custom)[^] for more details.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900