cag166

cag166


  • Name: [not set]
  • Favorite Languages: [not set]
  • Website: [not set]
  • Location: [not set]
  • About Me: [not set]

Recent Comments

  • C# Tutorial - Using The Built In OLEDB CSV Parser
    07/05/2010 - 23:31

    Thanks for the article.
    Having a problem trying to read a list of reference numbers from a CSV file. When the 'number' contains an alpha the data is not being read so there's no way to notify the user about bad data. It works fine if the data is in an Excel spreadsheet.
    Sample Data:
    ITEM_REF_NO
    905893
    1000O
    913798

    Second record contains an alpha O at the end of the number but this data does not appear in the datatable.

    My code is C# and is copied from the sample.
    string full = Path.GetFullPath(strFileName);
    string file = Path.GetFileName(full);
    string dir = Path.GetDirectoryName(full);
    //create the "database" connection string
    string connString = "Provider=Microsoft.Jet.OLEDB.4.0;"
    + "Data Source=\"" + dir + "\\\";"
    + "Extended Properties=\"text;HDR=No;FMT=Delimited\"";

    //create the database query
    string query = "SELECT * FROM [" + file + "]";

    DataTable dt = new DataTable();
    OleDbDataAdapter adpCSV = new OleDbDataAdapter(query, connString);

    try
    {
    adpCSV.Fill(dt);
    // view the datatable here and it contains 3 rows but the second row is empty

    Any ideas how to get this working?