Hello
I am trying to import from a csv file using the ole jet engine. All seems to work fine.
The issue I am having though is if someone has a single quote char in the title of the file eg matt's file.csv. or they have muliple periods in the file name eg Jim.File.csv
The way I am doing it is -
C#
oledbConnection conn = new oledbconnection ();
conn.Connection String = string.Format(" Provider=Micros oft.Jet.OLEDB.4 .0;Data Source={0};Exte nded Properties={1}T ext;Excel 8.0;HDR=No;{2}" , System.IO.Path. GetDirectoryNam e(FileName), (char)34, (char)34);
conn.open();
string CommandText = String.Format(" Select * from {0}", System.IO.Path. GetFullPath(Fil eName));
oledbdataadapte r da = new oledbdataadatpe r(CommandText, conn);
DataTable dt = new DataTable();
da.Fill(dt);
it crashes right there. saying Syntax error in from clause.
One other issue that this same code has is when someone has a csv with the """blah, blah""" which should display "blah, blah" when i grab the string. but it just crashes with another issue stating Syntax error in from clause.
By the way for the first issue. I have already tried separately building the path then adding double quotes around the file name, I have also tried doing a filename.replac e("'", "''") and that has not worked either. As well I also tried putting double quotes around the entire path and file name eg("C:\\users\\ test.test.csv")
I am trying to import from a csv file using the ole jet engine. All seems to work fine.
The issue I am having though is if someone has a single quote char in the title of the file eg matt's file.csv. or they have muliple periods in the file name eg Jim.File.csv
The way I am doing it is -
C#
oledbConnection conn = new oledbconnection ();
conn.Connection String = string.Format(" Provider=Micros oft.Jet.OLEDB.4 .0;Data Source={0};Exte nded Properties={1}T ext;Excel 8.0;HDR=No;{2}" , System.IO.Path. GetDirectoryNam e(FileName), (char)34, (char)34);
conn.open();
string CommandText = String.Format(" Select * from {0}", System.IO.Path. GetFullPath(Fil eName));
oledbdataadapte r da = new oledbdataadatpe r(CommandText, conn);
DataTable dt = new DataTable();
da.Fill(dt);
it crashes right there. saying Syntax error in from clause.
One other issue that this same code has is when someone has a csv with the """blah, blah""" which should display "blah, blah" when i grab the string. but it just crashes with another issue stating Syntax error in from clause.
By the way for the first issue. I have already tried separately building the path then adding double quotes around the file name, I have also tried doing a filename.replac e("'", "''") and that has not worked either. As well I also tried putting double quotes around the entire path and file name eg("C:\\users\\ test.test.csv")
Comment