Leggere un file CSV in C#
L'esempio C# mostra come leggere un file in formato CSV tramite il driver ODBC Microsoft Text Driver e caricarlo in un DataSet
C#
//read a CSV file
string fileName = @"c:\temp\test1.csv";
DataSet ds = new DataSet ();
string strConnString= "DRIVER={Microsoft Text Driver (*.txt; *.csv)};FileName="
+ fileName
+ ";Extensions=asc,csv,tab,txt;Persist Security Info=False";
using (OdbcConnection cnn = new OdbcConnection(strConnString))
{
cnn.Open();
string sql = string.Format("select * from [{0}]"
, System.IO.Path.GetFileName(fileName));
OdbcDataAdapter da = new OdbcDataAdapter(sql, cnn);
//fill dataset
da.Fill(ds, "TblCsv");
}