title: c# adding row that already belongs to a datatable
body: <p>I have a datatable <code>DTgraph</code>, that datatable has a column named <code>Campaign</code>. that column could have one of three unique values, which are <code>IVR, City</code>, City2`. So the rows are like this:</p>
  
  <p>I have a datatable has data like this format</p>
  
  <pre><code>........ IVR........
  
  .........IVR........
  
  **.........IVR........**
  
  .........City1......
  
  .........City1......
  
  **.........City1......**
  
  .........City2......
  
  .........City2......
  
  **.........City2......**
  </code></pre>
  
  <p>I want to take the last row of each unique value for that column, In other words, I want to take the rows that are bold. I did almost everything like this:</p>
  
  <pre><code>var cRows = new Dictionary&lt;string, DataRow&gt;(StringComparer.InvariantCultureIgnoreCase);
  
  foreach (DataRow oRow in DTgraph.Rows)
  {
      var sKey = oRow["Campaign"].ToString();
  
      if (!cRows.ContainsKey(sKey))
      {
          cRows.Add(sKey, oRow);
      }
      else
      {
          cRows[sKey] = oRow;
      }
  }
  
  var oNewTable = DTgraph.Clone();
  
  foreach (var oRow in cRows.Values)
  {
      oNewTable.Rows.Add(oRow);
  }
  </code></pre>
  
  <p>As you see, I put the data in dictionary and transferred the dictionary to a datatable at the end.</p>
  
  <p>My problem is that on this line: </p>
  
  <pre><code>cRows.Add(sKey, oRow);
  </code></pre>
  
  <p>I get an error:</p>
  
  <blockquote>
    <p>The row is already belongs to another datatable</p>
  </blockquote>
  
  <p><strong>Note</strong>: I need to solve that exception, I don't need a new way of doing my goal</p>
  
  <p><strong>Note</strong>: I was wrong, the exception is on this line </p>
  
  <pre><code>oNewTable.Rows.Add(oRow);
  </code></pre>