title: Adding and Updating DataTable columns in C#
body: <p>I am trying to add columns to a DataTable.</p>
  
  <p>I can add the columns just fine.  However, when I loop through the rows setting values for these new columns, it doesn't update the DataRow.ItemArray.  Here is my code:</p>
  
  <pre><code>private void UpdateTabularDataTable(SqlConnection connection)
  {
        // when I add these columns, it works fine.
        var rejectedColumn = table.Columns.Add(Constants.RejectedUiColumnName, typeof(bool));
        var rejectedReasonColumn = table.Columns.Add(Constants.RejectedReasonUiColumnName, typeof(string));
  
        foreach (var row in table.Rows.Cast&lt;DataRow&gt;())
        {
          var contourId = (Guid)row.ItemArray[0];
  
          // this is a Dictionary of objects which are rejected.  The others are accepted.
          string rejectedReason;
          var isRejected = _rejectedParticleReasonHolder.TryGetValue(contourId.ToString(), out rejectedReason);
  
          // these assignments don't work.  There's no exception; they 
          // just don't update the relevant values on the object.
          // Also, I verified that the Ordinal values are correct.
          row.ItemArray[rejectedColumn.Ordinal] = isRejected;
          row.ItemArray[rejectedReasonColumn.Ordinal] = rejectedReason;
  
        }
      }
    }
  
  }
  </code></pre>