Reading CSV file using OleDB not reading 1st line

T

tshad

I have a program that is reading a csv file into a dataset. I want it to
read the 1st line as data. But it ignores it.

I have the Connection set up as:

OleDbConnection csvConnection = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
csvPath + ";Extended
Properties=\"Text;HDR=Yes;FMT=Delimited\"");

or

OleDbConnection csvConnection = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
csvPath + ";Extended
Properties=\"Text;HDR=No;FMT=Delimited\"");

Either way (with HDR set to Yes or No), it doesn't read the 1st line.

Is there something else I need to do to get it to read that line?

I am reading it as:

da = new OleDbDataAdapter("Select * from " +
strFile,csvConnection);
da.Fill(ds);

Thanks,

Tom
 
T

tshad

Figured it out - I ran into this a long time ago.

The problem is that you can't put the path in both the OleDbConnection
(which you have to, I believe) and the Select statement.

So I needed to change the statement from:

da = new OleDbDataAdapter("Select * from " + strFile,csvConnection);

to:

da = new OleDbDataAdapter("Select * from " +
Path.GetFileName(strFile),csvConnection);

I suppose if you put part of the path in the connection string and the rest
of the path in the Select statement it might work, but I am not sure.

Why it ignores the HDR parameter, I don't know. I would think it wouldn't
find the file at all if there were a conflict.

Thanks,

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top