title: System.Data.DuplicateNameException: A column named 'Item' already belongs to this DataTable
body: <p>I have an extension method to turn an IEnumerable into a data table and it is throwing this exception. <code>System.Data.DuplicateNameException: A column named 'Item' already belongs to this DataTable.</code> What's confusing is that there is not a column named 'Item' in this table, or at least there shouldn't be because the SqlTable it was created from does not have an 'Item' column.</p>
  
  <pre><code>public static DataTable ToDataTable&lt;T&gt;(this IEnumerable&lt;T&gt; items)
  {
      var dataTable = new DataTable(typeof(T).Name);
  
      var props = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);
  
      foreach (var prop in props)
      {
          dataTable.Columns.Add(prop.Name, prop.PropertyType);
      }
  
      foreach (var item in items)
      {
          var values = new object[props.Length];
          for (var i = 0; i &lt; props.Length; i++)
          {
              values[i] = props[i].GetValue(item, null);
          }
  
          dataTable.Rows.Add(values);
      }
  
      return dataTable;
  }
  </code></pre>
  
  <p>This extention method has been working except until now when I use it with a method that takes in a sql table and makes it a datatable, then turns the data table into and IEnumerable to update one column and then uses the extenstion method on the Ienumerable to turn it back into a datatable. </p>
  
  <pre><code>var strSqlQuery = "Select * FROM " + strTableName; 
  
  var dataTable = Database.CreateDataTableFromDatabaseTable(strSqlQuery);
  var ocRows = dataTable.AsEnumerable(); // turn the data table into an enumerable we can sqlbulkcopy dump later
  
  foreach (var dataRow in ocRows)
  {
      if (dataRow[4].ToString().Contains("COMPLETED")) continue;
      // Generate and Save Needed Hashes for this Node
      // This is the algorithm to generate the hash
      var md5Hash = MD5.Create();
      var profileId = Database.GetProfileIdByEndPage(dataRow[3].ToString(), false);
      var endPageId = Database.GetEndPageId(navigationProfileId);
      var strValuesForObjectHash = string.IsNullOrEmpty(dataRow[6].ToString()) // if the "id" is null or empty use xpath
          ? endPageId + "," + dataRow[7]  // use the xpath for the object hash, not the "id"
          : endPageId + "," + dataRow[6]; // if the id has a value use the id for the object hash
      var currentObjectHash = strValuesForObjectHash.GetMd5Hash(md5Hash);
      dataRow[1] = currentObjectHash;
  }
  </code></pre>
  
  <p>I tried in the extension method to check if the column had already been added but then got 
  <code>System.Reflection.TargetParameterCountException: Parameter count mismatch.</code></p>
  
  <pre><code>foreach (var prop in props)
  {
      if (dataTable.Columns.Contains(prop.Name))
      dataTable.Columns.Add(prop.Name, prop.PropertyType);
  }
  </code></pre>
  
  <p>How can I use the DataTable as enumerable to update the one column for each row and make it into a DataTable again?</p>