Reading CSV file in Dataset WITHOUT headers

I have a little problem with the following code. The code works fine if I do not enable HDR = NO. The CSV that will be used for this WEB application will not have header information. How can I read it in a dataset and create static column names?

I get this error when running the code below: Could not find installable ISAM.

Here is my code:

FileUpload1.SaveAs(System.IO.Path.Combine(target, FileUpload1.FileName));

string connString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=Text; HDR=NO;", System.IO.Path.GetDirectoryName(target + "\\" + FileUpload1.FileName));
string cmdString = string.Format("SELECT * FROM {0}", System.IO.Path.GetFileName(target + "\\" + FileUpload1.FileName));

OleDbDataAdapter dataAdapter = new OleDbDataAdapter(cmdString, connString);
DataSet dataSet = new DataSet();
dataAdapter.Fill(dataSet);

GridView1.DataSource = dataSet.Tables[0];
GridView1.DataBind();

I would be grateful for any help.

Thank.

+3
source share
1 answer

Try Extended Properties=Text; HDR=NO;changing to Extended Properties=""text;HDR=No""or Extended Properties=\"text;HDR=No\".

This error occurs when the syntax of the connection string is incorrect. This usually happens when using several parameters of advanced properties.

+2
source

All Articles