Articles → ADO.NET → Reading CSV Files In Ado.Net

Reading CSV Files In Ado.Net






CSV File


Picture showing the sample CSV file
Click to Enlarge




Implementation






Provider=Microsoft.Jet.OLEDB.4.0;Data Source=<folder_Name>;Extended Properties='text;HDR=Yes';






string connectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties='text;HDR=Yes';", @ "D:\");
string commandText = "select * from abc.csv"; 
using(OleDbConnection conn = new OleDbConnection(connectionString)) {
  using(OleDbDataAdapter adap = new OleDbDataAdapter(commandText, conn)) {
    conn.Open();
    using(DataSet ds = new DataSet()) {
      adap.Fill(ds);
    }
  }
}





Output


Picture showing the records of CSV file in the data table
Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Sunday, December 18, 2011

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250