title: Read fixed width text file into datatable row by row - C#
body: <p>I have a large fixed width text file, I want to read it row by row and insert into a datatable, or just read it into a datatable. how can I assign that from which to which position one column will be?</p>
  
  <p>I also have to perform some action like trim the extra space of columns for every record.</p>
  
  <p>I tried this code but it gives me datatable with just 3 columns instead of 15</p>
  
  <pre><code>string sourcePath = @"c:\\";
  string filename = "file.txt";
  
  DataTable dt;
  
  //Create OleDb connection object
  using (OleDbConnection cn = new OleDbConnection(@"Provider=Microsoft.Jet.OleDb.4.0;" +
              "Data Source=" + sourcePath + ";Extended Properties=\"Text;\""))
  {
      // Open connection 
      cn.Open();
  
      // Create OleDb Adapter object 
      using (OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM " + filename, cn))
      {
          dt = new DataTable("Records");
          adapter.Fill(dt);
  
          // Display results
          dataGridView1.DataSource = dt;
      }
  }
  </code></pre>
  
  <p>Sample Data</p>
  
  <p>Sample    Name.......~Address~City~State~12345                                         Contact Name        123-456-7890          Type           Payment
  Sample    Name.......~Address~City~State~12345                                         Contact Name        123-456-7890          Type           Payment
  Sample    Name.......~Address City~State~12345                                         Contact Name        123-456-7890          Type           Payment
  Sample    Name.......~Address City~State~12345                                         Contact Name        123-456-7890          Type           Payment</p>
  
  <p>There is a lot spaces in between..</p>