title: Compare and delete datatable row using C#:
body: <p>I have two tables such as DTTable1 and  DTTable2. It has the following records.</p>
  
  <p>DTTable1:</p>
  
  <pre><code>    ItemID     Specification    Amount
     ---------  ---------------  ---------
        1             A             10
        1             B             20
        1             C             30
  </code></pre>
  
  <p>DTTable1:</p>
  
  <pre><code>    ItemID     Specification    Amount
     ---------  ---------------  ---------
        1             A             10
        1             B             20
        1             C             30
        2             A             10
        2             B             20
        3             A             10
        3             B             20
  </code></pre>
  
  <p>Here I want to compare these two tables. If DTTable1 records present in DTTable2(consider only ItemID) then remove the corresponding rows which has the ItemID same as DTTable1.</p>
  
  <p>I have tried foreach and forloop. 
  Using ForEach:</p>
  
  <pre><code>   foreach (DataRow DR in DTTable2.Rows)
     {
        if (DR["ItemID"].ToString() == DTTable1.Rows[0]["ItemID"].ToString())
        {
             DTTable2.Rows.Remove(DR);                            
        }
     }
     DTTable2.AcceptChanges();
  </code></pre>
  
  <p>It showed the error,
         "Collection was modified; enumeration operation might not execute". So I used For Loop, It also not given the desired result.</p>
  
  <p>Using For Loop:</p>
  
  <pre><code>   for (int i = 0; i &lt; DTTable2.Rows.Count; i++)
     {
         if (DTTable2.Rows[i]["ItemID"].ToString() == DTTable1.Rows[0]["ItemID"].ToString())
         {
             DTTable2.Rows.RemoveAt(i);
         }
     }
     DTTable2.AcceptChanges();
  </code></pre>
  
  <p>But sometimes, the second row doesn't remove from the table. I get the final DataTable as</p>
  
  <pre><code>    ItemID     Specification    Amount
     ---------  ---------------  ---------
        1             B             20
        2             A             10
        2             B             20
        3             A             10
        3             B             20
  </code></pre>
  
  <p>How to solve this? What is the simplest method to do this?</p>