Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>One possibility would be to use the DataTable class build in filtering. You can define a dynamic filter and apply it to the DataTable object. The dynamic filter language is something like a subset of SQL, it has LIKE and other SQL keywords. An example of filtering code:</p> <pre><code>var dt = new DataTable("test"); dt.Columns.Add("A", typeof(string)); dt.Columns.Add("B", typeof(string)); dt.Rows.Add(new object[] { "a", "1" }); dt.Rows.Add(new object[] { "a", "2" }); var rows = dt.Select("B = '2'"); </code></pre> <p>This way you can define the filter and apply it to both tables and compare only the result set and not every entry. The result is an array of Rows.</p> <p>I used it in a project, that has DataTable objects containing more than 2K entries each and the performance is really good.</p> <p>Another possibility would be to use LINQ to filter the data. You can query the DataTable's rows like this:</p> <pre><code>var rows = (from DataRow dr in dt.Rows where dr["B"] == "2" select dr).ToList(); </code></pre> <p>This query returns the same result as the direct filtering. You can apply again the same approach here to check the mathching result only. </p> <hr> <p>If i understood your question correctly, a possible solution to your problem could look like this:</p> <pre><code>// test DataTable objects for the example var dt1 = new DataTable("Table 1"); dt1.Columns.Add("title", typeof(string)); dt1.Columns.Add("number", typeof(int)); dt1.Columns.Add("subnum1", typeof(int)); dt1.Columns.Add("subnum2", typeof(int)); dt1.Rows.Add(new object[] { "a", 1111, 1, 1 }); // Exact match! dt1.Rows.Add(new object[] { "b", 2222, 1, 1 }); // Only NUMBER match dt1.Rows.Add(new object[] { "b", 2222, 2, 2 }); // Only NUMBER match dt1.Rows.Add(new object[] { "d", 3333, 1, 1 }); // Exact match! dt1.Rows.Add(new object[] { "d", 3333, 1, 2 }); dt1.Rows.Add(new object[] { "d", 3333, 2, 1 }); var dt2 = new DataTable("Table 2"); dt2.Columns.Add("number", typeof(int)); dt2.Columns.Add("subnum1", typeof(int)); dt2.Columns.Add("subnum2", typeof(int)); dt2.Rows.Add(new object[] { 1111, 1, 1 }); // Exact match! dt2.Rows.Add(new object[] { 2222, 0, 5 }); // Only NUMBER match dt2.Rows.Add(new object[] { 3333, 1, 1 }); // Exact match! dt2.Rows.Add(new object[] { 3333, 0, 0 }); // Only NUMBER match foreach (DataRow row in dt1.Rows) { var matches = dt2.Select(string.Format("number = {0} and subnum1 = {1} and subnum2 = {2}", row["number"], row["subnum1"], row["subnum2"])); if (matches.Count() &gt; 0) { Console.WriteLine(row["title"]); } else { var fallback = dt2.Select(string.Format("number = {0}", row["number"])); if (fallback.Count() &gt; 0) { Console.WriteLine(" &gt; " + row["title"]); } } } </code></pre> <p>The output in this case is:</p> <pre><code>a &gt; b &gt; b d &gt; d &gt; d </code></pre> <p>What values shoule be written to the output is up to you - at the point where the match is found you have all that you need.</p>
    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