connect to a csv file using odbc

This is one of my Most Visited Post So i am Publishing this again . Connecting to CSV file in C#
. Here is some sample C# code that works with CSV files using ODBC (using System.Data.Odbc):

string strConn = @"Driver={Microsoft Text Driver (*.txt; *.csv)};" +
"Dbq=C:;Extensions=csv,txt";

try
{
OdbcConnection objCSV = new OdbcConnection(strConn);
objCSV.Open();

OdbcCommand oCmd = new OdbcCommand("select column1,column2 " +
"from THECSVFILE.CSV", objCSV);
OdbcDataReader oDR = oCmd.ExecuteReader();

while (oDR.read())
{
// Do something
}
oDR.Close();
oCmd.Dispose();
objCSV.Close();
}
catch {}

Use the name of the CSV file in the SQL Statement itself, as in the code above. It will read the CSV file

If you have any queries on connectionstring . visit www.connectionstrings.com

Regards,
Elam