use
DataTable.Select Method (String, String) (System.Data)[
^] to find the rows in the target table so that you shall eliminate the looping.
try this, take care of validation and casting etc.
foreach (DataRow row in dt1.Rows)
{
var id = row["YourIDColumn"];
DataRow[] rows = dt2.Select("YourIDColumn ='" + id + "'");
if (rows.Length == 1)
{
if (rows[0]["YourIDColumn"] == id)
{
}
else
{
}
}
else
{
}
}