Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The key is using System.Data.DataRelation to join your 2 datatables on a common column (or columns).</p> <p>Here's some code derived from a post at <a href="http://kseesharp.blogspot.com/2007/12/compare-2-datatables-and-return-3rd.html" rel="nofollow noreferrer">KC's See Sharp Blog</a></p> <pre><code>public DataTable GetImproperRecords(DataTable ProperRecords, DataTable ImproperRecords) { DataTable relatedTable = new DataTable("Difference"); try { using (DataSet dataSet = new DataSet()) { dataSet.Tables.AddRange(new DataTable[] { ProperRecords.Copy(), ImproperRecords.Copy() }); DataColumn properColumn = new DataColumn(); properColumn = dataSet.Tables[0].Columns[1]; // Assuming subsNumber is at index 1 DataColumn improperColumn = new DataColumn(); improperColumn = dataSet.Tables[1].Columns[0]; // Assuming subsNumber is at index 0 //Create DataRelation DataRelation relation = new DataRelation(string.Empty, properColumn, improperColumn, false); dataSet.Relations.Add(relation); //Create columns for return relatedTable for (int i = 0; i &lt; ImproperRecords.Columns.Count; i++) { relatedTable.Columns.Add(ImproperRecords.Columns[i].ColumnName, ImproperRecords.Columns[i].DataType); } relatedTable.BeginLoadData(); foreach (DataRow parentrow in dataSet.Tables[1].Rows) { DataRow[] childrows = parentrow.GetChildRows(relation); if (childrows != null &amp;&amp; childrows.Length &gt; 0) relatedTable.LoadDataRow(parentrow.ItemArray, true); } relatedTable.EndLoadData(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } return relatedTable; } </code></pre>
 

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