Read alphanumeric characters from csv file in C#

Posted by Prasad on Stack Overflow See other posts from Stack Overflow or by Prasad
Published on 2010-04-13T07:57:38Z Indexed on 2010/04/13 8:03 UTC
Read the original article Hit count: 379

Filed under:
|
|
|
|

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;IMEX=1\"";

        //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.

© Stack Overflow or respective owner

Related posts about c#

Related posts about csv