title: Creating a DataTable from CSV File
body: <p>I'm working on a project and I need to read a CSV file and then fill a DataSet with its data. I've been searching and I have found some interesting things in OleDB. </p>
  
  <p>I have a class CSVReader:</p>
  
  <pre><code>class CSVReader
  {
      public DataTable GetDataTable(string filePath)
      {
          OleDbConnection conn = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0; Data Source = " + Path.GetDirectoryName(filePath) + "; Extended Properties = \"Text;HDR=YES;FMT=Delimited\"");
          conn.Open();
          string strQuery = "SELECT * FROM [" + Path.GetFileName(filePath) + "]";
          OleDbDataAdapter adapter = new OleDbDataAdapter(strQuery, conn);
          DataSet ds = new System.Data.DataSet("CSV File");
          adapter.Fill(ds);
          return ds.Tables[0];
      }
  }
  </code></pre>
  
  <p>And I call it from here:</p>
  
  <pre><code>CSVReader datareader = new CSVReader();
  DataTable dt = datareader.GetDataTable(filepath);
  </code></pre>
  
  <p>The problem is that it parse the first line (the header line) like JUST ONE identifier for the column, I mean: This is the header of the CSV file:</p>
  
  <pre><code>Name, Product Name, Server, Vendor, Start Time, End Time, Host Name, User Name, Project Name, Usage time (hours)
  </code></pre>
  
  <p>And after it, there is all the data separated by commas. </p>
  
  <p>When I read the file, fill the dataset and print <em>dt.Columns.Count</em> it shows that it only have 1 column. </p>
  
  <p>Any help?</p>
  
  <p>Thanks in advance.</p>