Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>My question: <em>"Must all row's fields match with the same row's fields of the other DataTable?"</em></p> <p>Your answer: <em>"no just the id"</em></p> <p>You can first check if both <code>DataTables</code> are null or both have the same row-count. Then you can use LINQ to determine if both have the same IDs using <a href="http://msdn.microsoft.com/en-us/library/bb300779.aspx" rel="nofollow"><code>Enumerable.Except</code></a>:</p> <pre><code>var dt1IDs = DT1.AsEnumerable().Select(r =&gt; r.Field&lt;int&gt;("id")); var dt2IDs = DT2.AsEnumerable().Select(r =&gt; r.Field&lt;int&gt;("id")); var diff = dt1IDs.Except(dt2IDs); var equal = DT1.Rows.Count == DT2.Rows.Count &amp;&amp; !diff.Any(); </code></pre> <p>Explanation: <code>diff.Any()</code> returns true when there's at least one id in DT1 that is not in DT2.</p> <p><strong>Edit</strong>: If the ID is <strong>not</strong> unique and might repeat you need to check whether all ID's in DT1 are also in DT2 and all IDs of DT2 are in DT1:</p> <pre><code>var DT1InDT2 = dt1IDs.Except(dt2IDs); var DT2InDT1 = dt2IDs.Except(dt1IDs); var equal = DT1.Rows.Count == DT2.Rows.Count &amp;&amp; !DT1InDT2.Any() &amp;&amp; !DT2InDT1.Any(); </code></pre> <p>This query is efficient anyway.</p> <hr> <p><strong>Edit2</strong>: I've just seen that i've misunderstood your requiremnet a little bit. You only want to know if the first table contains the second, not vice-versa. </p> <pre><code>var DT2IdNotInDT1 = dt2IDs.Except(dt1IDs); var equal = !DT2IdNotInDT1.Any(); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload