Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Compare 2 Datatables

Compare 2 Datatables

Scheduled Pinned Locked Moved C#
csharptutorial
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jojoba20
    wrote on last edited by
    #1

    How to compare two dataTables in C#. I have this code but it returns NULL.

    DataTable dtReturn = new DataTable();

            dtTarget.Merge(dtSource);
            BindingContext\[dtTarget\].EndCurrentEdit();
            dtReturn = new DataTable(); 
            dtReturn = dtTarget.GetChanges(DataRowState.Added);
    
    A 1 Reply Last reply
    0
    • J jojoba20

      How to compare two dataTables in C#. I have this code but it returns NULL.

      DataTable dtReturn = new DataTable();

              dtTarget.Merge(dtSource);
              BindingContext\[dtTarget\].EndCurrentEdit();
              dtReturn = new DataTable(); 
              dtReturn = dtTarget.GetChanges(DataRowState.Added);
      
      A Offline
      A Offline
      Andre Kraak
      wrote on last edited by
      #2

      From what I read here[^], you need to switch the DataTable for the Merge function. Try this:

      dtSource.Merge(dtTarget);
      DataTable dtReturn = dtTarget.GetChanges();

      0100000101101110011001000111001011101001

      J 1 Reply Last reply
      0
      • A Andre Kraak

        From what I read here[^], you need to switch the DataTable for the Merge function. Try this:

        dtSource.Merge(dtTarget);
        DataTable dtReturn = dtTarget.GetChanges();

        0100000101101110011001000111001011101001

        J Offline
        J Offline
        jojoba20
        wrote on last edited by
        #3

        Thanks for ans ! But even i have try this and returns NULL values too.

        A 1 Reply Last reply
        0
        • J jojoba20

          Thanks for ans ! But even i have try this and returns NULL values too.

          A Offline
          A Offline
          Andre Kraak
          wrote on last edited by
          #4

          I just read this Comparing Datasets using Linq[^] and it states that

          To resolve this issue we contacted the Microsoft Support team and after a few days of email exchange, we got the following message: ”I think the root of the issue is that Merge does not change row state. If you create a dataset, then manually change a row value, then row state is tweaked and GetChanges() behaves as expected.”

          so it looks like the merge option is not going to work. Perhaps you can use the LINQ option given.

          0100000101101110011001000111001011101001

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups