Lettura di un file CSV tramite ODBC

Posted by: ollie10 7/20/2009 4:06 PM

In questo esempio vediamo come leggere un file in formato CSV tramite il driver ODBC Microsoft Text Driver e caricarlo in un DataSet

//LETTURA DA FILE CSV
string fileName = @"c:\cartella\miofile.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);
	// RIEMPIMENTO DATASET
	da.Fill(ds, "TblCsv");
}
Tags: , , , ,
Categories: Asp.NET - C# | Sviluppo Web
Permalink | Comments (0)
RSS comment feed

Comments

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading