i want to read csv file using c#.
Microsoft has standard driver for text file MS-Text driver. You can use and load effortlessly.
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 {}
You could try out A Fast CSV Reader
It's a CodeProject project and should fit your needs.
精彩评论