troubleshooting Question

How to find a deleted row from two DataTables in C#

Avatar of dominicwong
dominicwong asked on
C#
5 Comments2 Solutions76 ViewsLast Modified:
I have two DataTables as follows.
The 3rd row is removed from the Table 1.
I would like to do a diff of the two tables, and get an answer to tell me that the row had been deleted.
I tried with the following code but it doesn't work. The result it gave me was 11 rows unchanged.

Any idea please. Thanks.

            table1.AcceptChanges();
            table2.AcceptChanges();
            table1.Merge(table2, true);

            if(added != null)
                Debug.WriteLine("added = " + added.Rows.Count);
            if (deleted != null)
                Debug.WriteLine("deleted = " + deleted.Rows.Count);
            if (detached != null)
                Debug.WriteLine("detached = " + detached.Rows.Count);
            if (modified != null)
                Debug.WriteLine("modified = " + modified.Rows.Count);
            if (unchanged != null)
                Debug.WriteLine("unchanged = " + unchanged.Rows.Count);
 Table1
          Key1                Key2                 Key3                Key4                Key5               Key6               Key7
    2063620735   2107319875   1418390997    270727583    270727583    652640566    369246503
    1630856750    515371590    416266794   2014872019   2014872019    532186611    504554590
     971040548   2107319875   1418390997   1037345008   1037345008    652640566    369246503  <-- Deleted
    1604012077   2107319875    416266794   2014872019   2014872019    532186611    369246503
    1604012077    515371590   1418390997    270727583   1037345008    652640566    369246503
    2063620735    515371590    416266794    421288522   2014872019    532186611    369246503
 
  Table2
          Key1                Key2                 Key3                Key4                Key5               Key6               Key7
    2063620735   2107319875   1418390997    270727583    270727583    652640566    369246503
    1630856750    515371590    416266794   2014872019   2014872019    532186611    504554590
    1604012077   2107319875    416266794   2014872019   2014872019    532186611    369246503
    1604012077    515371590   1418390997    270727583   1037345008    652640566    369246503
    2063620735    515371590    416266794    421288522   2014872019    532186611    369246503
ASKER CERTIFIED SOLUTION
Naitik Gamit
Senior Software Developer
Join our community to see this answer!
Unlock 2 Answers and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros