Reading CSV file using OleDB not reading 1st line

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • tshad

    Reading CSV file using OleDB not reading 1st line

    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=Micr osoft.Jet.OLEDB .4.0;Data Source=" +
    csvPath + ";Extended
    Properties=\"Te xt;HDR=Yes;FMT= Delimited\"");

    or

    OleDbConnection csvConnection = new
    OleDbConnection ("Provider=Micr osoft.Jet.OLEDB .4.0;Data Source=" +
    csvPath + ";Extended
    Properties=\"Te xt;HDR=No;FMT=D elimited\"");

    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 OleDbDataAdapte r("Select * from " +
    strFile,csvConn ection);
    da.Fill(ds);

    Thanks,

    Tom



  • Marc Gravell

    #2
    Re: Reading CSV file using OleDB not reading 1st line

    Can DataTable read from an IDataReader? I recommend:


    Marc

    Comment

    • tshad

      #3
      Re: Reading CSV file using OleDB not reading 1st line

      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 OleDbDataAdapte r("Select * from " + strFile,csvConn ection);

      to:

      da = new OleDbDataAdapte r("Select * from " +
      Path.GetFileNam e(strFile),csvC onnection);

      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
      "tshad" <tshad@dslextre me.comwrote in message
      news:eZURykqaIH A.4880@TK2MSFTN GP03.phx.gbl...
      >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=Micr osoft.Jet.OLEDB .4.0;Data Source=" +
      csvPath + ";Extended
      Properties=\"Te xt;HDR=Yes;FMT= Delimited\"");
      >
      or
      >
      OleDbConnection csvConnection = new
      OleDbConnection ("Provider=Micr osoft.Jet.OLEDB .4.0;Data Source=" +
      csvPath + ";Extended
      Properties=\"Te xt;HDR=No;FMT=D elimited\"");
      >
      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 OleDbDataAdapte r("Select * from " +
      strFile,csvConn ection);
      da.Fill(ds);
      >
      Thanks,
      >
      Tom
      >
      >
      >

      Comment

      Working...