Steve
Steve

Reputation: 1058

Reading CSV file into Dataset WITHOUT headers

I have a small problem with the following code. The code works fine if I don't include HDR=NO. The CSV that will be used for this WEB app will not have any header info. How can I read it into 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 so far:

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 appreciate any help.

Thank you.

Upvotes: 3

Views: 4248

Answers (1)

Renatas M.
Renatas M.

Reputation: 11820

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

This error is generated when the syntax of the connection string is incorrect. This commonly occurs when using multiple Extended Properties parameters.

Upvotes: 2

Related Questions