views:

230

answers:

2

I am using the following code to read my csv file:

public DataTable ParseCSV(string path)
    {
        if (!File.Exists(path))
            return null;

        string full = Path.GetFullPath(path);
        string file = Path.GetFileName(full);
        string dir = Path.GetDirectoryName(full);

        //create the "database" connection string 
        string connString = "Provider=Microsoft.ACE.OLEDB.12.0;"
          + "Data Source=\"" + dir + "\\\";"
          + "Extended Properties=\"text;HDR=Yes;FMT=Delimited\"";

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

        //create a DataTable to hold the query results
        DataTable dTable = new DataTable();

        //create an OleDbDataAdapter to execute the query
        OleDbDataAdapter dAdapter = new OleDbDataAdapter(query, connString);

        //fill the DataTable
        dAdapter.Fill(dTable);

        dAdapter.Dispose();

        return dTable;
    }

But the above doesn't reads the alphanumeric value from the csv file. it reads only i either numeric or alpha.

Whats the fix i need to make to read the alphanumeric values? Please suggest.

+1  A: 

I suggest you use A Fast CSV Reader which does not have this issue and is much more faster.

Giorgi
A: 

Remove IMEX=1 from the connection string. I don't think you need it for CSV files.

Mr Roys
i tried that too, but its still the same result
Prasad
Strange, I was doing something at work and used roughly the same code but with a different connection string for a comma-delimited file - Provider=Microsoft.Jet.OLEDB.4.0;Data Source=DirName;Extended Properties='text;HDR=Yes;FMT=Delimited'
Mr Roys