title: Add columns to a datatable in c#?
body: <p>I have a csv reader class that reads a <code>.csv</code> file and its values.... I have created <code>datatable</code> out of it... Consider my <code>Datatable</code> contains three header columns <code>Name,EmailId,PhoneNo</code>.... The values have been added successfully.... Now i want to add two columns <code>IsDeleted,CreatedDate</code> to this <code>datatable</code>... I have tried this but it doesn't seem to work,</p>
  
  <pre><code>    foreach (string strHeader in headers)
      {
          dt.Columns.Add(strHeader);
      }
      string[] data;
      while ((data = reader.GetCSVLine()) != null)
      {
          dt.Rows.Add(data);
      }
      dt.Columns.Add("IsDeleted", typeof(byte));
      dt.Columns.Add(new DataColumn("CreatedDate", typeof(DateTime)));
      foreach (DataRow dr in dt.Rows)
      {
          dr["IsDeleted"] = Convert.ToByte(0);
          dr["CreatedDate"] = Convert.ToDateTime(System.DateTime.Now.ToString());
          dt.Rows.Add(dr);
      }
  </code></pre>
  
  <p><code>dt.Rows.Add(dr);</code> shows an error saying <code>This row already belongs to this table.
  </code>.... </p>
  
  <p><a href="http://www.imagechicken.com/uploads/1273560975016964800.jpg" rel="nofollow noreferrer">alt text http://www.imagechicken.com/uploads/1273560975016964800.jpg</a></p>