How do I compare two datatables
<p>I have a datatable that will consist of 72 columns.</p>

<p>I will download it in the excel sheet using VSTO, which works fine.</p>

<p>Now the user will change either one of these rows or all of these rows and will also insert a fresh row.</p>

<p>Considering the datatable downloaded first to be dtA, and the one that has been modified in the excel sheet to be dtB.</p>

<p>I want to compare dtA and dtB.</p>

<p>I need to find out all the rows in dtB that do not exist in dtA.</p>

<p>I cant put foreach loop for each and every single row and evaluate as its a very untidy way of coding.</p>

<p>What is a better way to do this?</p>

<p>I did this way,</p>

<pre><code>    DataTable dtA = new DataTable();
    dtA.Columns.Add("ENo");
    dtA.Columns.Add("ENo1");
    dtA.Columns.Add("ENo2");
    dtA.Columns.Add("ENo3");
    dtA.Columns.Add("ENo4");

    for (int i = 0; i &lt; 5; i++)
    {
        DataRow dr = dtA.NewRow();
        dr[0] = "Part 0 " + i.ToString();
        dr[1] = "Part 1 " + i.ToString();
        dr[2] = "Part 2 " + i.ToString();
        dr[3] = "Part 3 " + i.ToString();
        dr[4] = "Part 4 " + i.ToString();
        dtA.Rows.Add(dr);
    }

    DataTable dtB = new DataTable();
    dtB.Columns.Add("ENo");
    dtB.Columns.Add("ENo1");
    dtB.Columns.Add("ENo2");
    dtB.Columns.Add("ENo3");
    dtB.Columns.Add("ENo4");

    for (int i = 5; i &lt; 10; i++)
    {
        DataRow dr = dtB.NewRow();
        dr[0] = "Part 0 " + i.ToString();
        dr[1] = "Part 1 " + i.ToString();
        dr[2] = "Part 2 " + i.ToString();
        dr[3] = "Part 3 " + i.ToString();
        dr[4] = "Part 4 " + i.ToString();
        dtB.Rows.Add(dr);
    }

    Response.Write("\n");
    Response.Write("dt A");
    Response.Write("\n");

    for (int i = 0; i &lt; dtA.Rows.Count; i++)
    {
        Response.Write(dtA.Rows[i][i].ToString());
        Response.Write("\n");
    }

    Response.Write("\n");
    Response.Write("dt B");
    Response.Write("\n");
    for (int i = 0; i &lt; dtB.Rows.Count; i++)
    {
        Response.Write(dtB.Rows[i][i].ToString());
        Response.Write("\n");
    }

    var VarA = dtA.AsEnumerable();
    var varB = dtA.AsEnumerable();

    var diff = VarA.Except(varB);
    Response.Write("except");
    foreach (var n in diff)
    {
        Response.Write(n.Table.Rows[0].ToString());

    }
</code></pre>

<p>But I do not know what to use in the foreach var,
What should I use pls?</p>
