In my ASP .NET application (using vb.net), I am getting error "syntax error in FROM clause" while querying a csv file using OLEDB connection.
connString = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" &
Server.MapPath(strFolderPath) & ";Extended
Properties=""Text;HDR=Yes;FMT=Delimited(,)"";"
conn = New OleDbConnection(connString)
query = "SELECT * FROM " & FilePath
'File path is C:DEVUploadsfile.csv
cmd = New OleDbCommand(query, conn)
da = New OleDbDataAdapter(cmd)
ds = New DataSet()
da.Fill(ds, "Putaway") 'here throwing error
Please how to solve it.
2
Answers
I solved the issue when directly used the csv file name without fullpath.
For starters, don’t use OLEDB to read CSV files. CSV files are just text files with Values Separated by Commas. Nothing more. You can read the data as text, or use a library like CsvHelper that parses CSV files and can even wrap them in a DataReader.
For example, using CsvHelper’s CsvDataReader class you can replace your code with :
This code will work both on Windows and Linux, both for 32-bit and 64-bit applications
The Access driver used in this code has several problems and is avoided in web applications. It was created to allow Office applications to read Access and Excel and CSV files, not for general use. CSV files are supported in a quirky way
That driver treats a folder as the "database" and file names in that folder as table names. That means that
FilePath
must befile.csv
, not the full pathC:DEVUploadsfile.csv