开发者

Reading CSV file into Dataset WITHOUT headers

开发者 https://www.devze.com 2023-03-10 15:42 出处:网络
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.

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 ins开发者_如何学编程tallable 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号