Comparing data from two data tables I have this code which compares data from two data tables.  It does this by using a primary column and inserting the new record from table2 to table1. This loop continues for a large number of tables. I want to optimize it. Kindly give suggestions.

foreach (DataRow drRow in table2.Rows)
{
    if(!table1.Rows.Contains(drRow["KeyId"]))
    {
        table1.ImportRow(drRow);
    }
}
For .net framework 3.5, you can have following code improvements:

foreach (var drRow in table2.Rows.Cast&lt;DataRow&gt;()
                      .Where(drRow =&gt; !table1.Rows.Contains(drRow["KeyId"]))) 
{
    table1.ImportRow(drRow); 
}



part of body can be converted to LINQ-expression
use "var" (implicitly typed) instead of "DataRow" (explicitly typed)