Compare 2 DataSets

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Al

    Compare 2 DataSets

    I'd like to know if there were any changes in the DataSet which was
    populated by reading XML file. 6 DataTables with data or just structure with
    no data inside of it.
    I think about this scenario:
    I create 2 datasets and populate both from the same XML file. Then the first
    one is used as DataSource for many controls and the second one is untouched.
    If there were some changes in the first one, I'd like to know it and would
    like to compare with the second one. I don't know how. Everything I need to
    know is just were there any changes or not. If yes I will ask the user if he
    wants to save them back into XML file.

    So the question again: How do I compare 2 datasets? Or maybe somebody can
    suggest a better way to catch changes?

    Thank you
    Al


  • Kerry Moorman

    #2
    RE: Compare 2 DataSets

    Al,

    The dataset has a HasChanges method that might work for you.

    Kerry Moorman


    "Al" wrote:
    I'd like to know if there were any changes in the DataSet which was
    populated by reading XML file. 6 DataTables with data or just structure with
    no data inside of it.
    I think about this scenario:
    I create 2 datasets and populate both from the same XML file. Then the first
    one is used as DataSource for many controls and the second one is untouched.
    If there were some changes in the first one, I'd like to know it and would
    like to compare with the second one. I don't know how. Everything I need to
    know is just were there any changes or not. If yes I will ask the user if he
    wants to save them back into XML file.
    >
    So the question again: How do I compare 2 datasets? Or maybe somebody can
    suggest a better way to catch changes?
    >
    Thank you
    Al
    >
    >
    >

    Comment

    • Al

      #3
      Re: Compare 2 DataSets

      Unfortunately HasChanges method returns True even right after populating
      DataSet from XML file. I do not know why.
      I also tried to populate another DataSet with GetChanges method. No success
      too - the resulting DataSet has rows in Tables. Do not know why either.

      Al


      "Kerry Moorman" <KerryMoorman@d iscussions.micr osoft.comwrote in message
      news:290AE629-D4CB-44CC-AB16-0BCD87C21CB1@mi crosoft.com...
      Al,
      >
      The dataset has a HasChanges method that might work for you.
      >
      Kerry Moorman
      >
      >
      "Al" wrote:
      >
      >I'd like to know if there were any changes in the DataSet which was
      >populated by reading XML file. 6 DataTables with data or just structure
      >with
      >no data inside of it.
      >I think about this scenario:
      >I create 2 datasets and populate both from the same XML file. Then the
      >first
      >one is used as DataSource for many controls and the second one is
      >untouched.
      >If there were some changes in the first one, I'd like to know it and
      >would
      >like to compare with the second one. I don't know how. Everything I need
      >to
      >know is just were there any changes or not. If yes I will ask the user if
      >he
      >wants to save them back into XML file.
      >>
      >So the question again: How do I compare 2 datasets? Or maybe somebody can
      >suggest a better way to catch changes?
      >>
      >Thank you
      >Al
      >>
      >>
      >>

      Comment

      • Kerry Moorman

        #4
        Re: Compare 2 DataSets

        Al,

        Have you tried calling the dataset's AcceptChanges method immediately after
        initially loading it? After that, HasChanges may correctly reflect changes
        since loading.

        Kerry Moorman


        "Al" wrote:
        Unfortunately HasChanges method returns True even right after populating
        DataSet from XML file. I do not know why.
        I also tried to populate another DataSet with GetChanges method. No success
        too - the resulting DataSet has rows in Tables. Do not know why either.
        >
        Al
        >
        >
        "Kerry Moorman" <KerryMoorman@d iscussions.micr osoft.comwrote in message
        news:290AE629-D4CB-44CC-AB16-0BCD87C21CB1@mi crosoft.com...
        Al,

        The dataset has a HasChanges method that might work for you.

        Kerry Moorman


        "Al" wrote:
        I'd like to know if there were any changes in the DataSet which was
        populated by reading XML file. 6 DataTables with data or just structure
        with
        no data inside of it.
        I think about this scenario:
        I create 2 datasets and populate both from the same XML file. Then the
        first
        one is used as DataSource for many controls and the second one is
        untouched.
        If there were some changes in the first one, I'd like to know it and
        would
        like to compare with the second one. I don't know how. Everything I need
        to
        know is just were there any changes or not. If yes I will ask the user if
        he
        wants to save them back into XML file.
        >
        So the question again: How do I compare 2 datasets? Or maybe somebody can
        suggest a better way to catch changes?
        >
        Thank you
        Al
        >
        >
        >
        >
        >
        >

        Comment

        • Al

          #5
          Re: Compare 2 DataSets

          I called AcceptChanges method as you suggested and now HasChanges returns
          False before any change as well as after changes.

          Al

          "Kerry Moorman" <KerryMoorman@d iscussions.micr osoft.comwrote in message
          news:715FAEDC-56EE-429B-9EA9-9AEE3FB352F2@mi crosoft.com...
          Al,
          >
          Have you tried calling the dataset's AcceptChanges method immediately
          after
          initially loading it? After that, HasChanges may correctly reflect changes
          since loading.
          >
          Kerry Moorman
          >
          >
          "Al" wrote:
          >
          >Unfortunatel y HasChanges method returns True even right after populating
          >DataSet from XML file. I do not know why.
          >I also tried to populate another DataSet with GetChanges method. No
          >success
          >too - the resulting DataSet has rows in Tables. Do not know why either.
          >>
          >Al
          >>
          >>
          >"Kerry Moorman" <KerryMoorman@d iscussions.micr osoft.comwrote in message
          >news:290AE62 9-D4CB-44CC-AB16-0BCD87C21CB1@mi crosoft.com...
          Al,
          >
          The dataset has a HasChanges method that might work for you.
          >
          Kerry Moorman
          >
          >
          "Al" wrote:
          >
          >I'd like to know if there were any changes in the DataSet which was
          >populated by reading XML file. 6 DataTables with data or just
          >structure
          >with
          >no data inside of it.
          >I think about this scenario:
          >I create 2 datasets and populate both from the same XML file. Then the
          >first
          >one is used as DataSource for many controls and the second one is
          >untouched.
          >If there were some changes in the first one, I'd like to know it and
          >would
          >like to compare with the second one. I don't know how. Everything I
          >need
          >to
          >know is just were there any changes or not. If yes I will ask the user
          >if
          >he
          >wants to save them back into XML file.
          >>
          >So the question again: How do I compare 2 datasets? Or maybe somebody
          >can
          >suggest a better way to catch changes?
          >>
          >Thank you
          >Al
          >>
          >>
          >>
          >>
          >>
          >>

          Comment

          • Al

            #6
            Re: Compare 2 DataSets

            I cannot be sure yet, but I think with your help I found what is wrong. I
            used to call AcceptChanges method every time I'm making changes in any
            DataTable. I was thinking that this method will save my changes in the
            DataSet only and without calling this method I will lose the changes I make.
            I commented all AcceptChanges calls and now HasChanges seems to work
            properly.
            So for now I do not need to to worry about losing any change I make and I
            just need to ask the user if he wants to save data into XML only in case
            when HasChanges returns True.

            Thank you very much

            Al

            "Kerry Moorman" <KerryMoorman@d iscussions.micr osoft.comwrote in message
            news:715FAEDC-56EE-429B-9EA9-9AEE3FB352F2@mi crosoft.com...
            Al,
            >
            Have you tried calling the dataset's AcceptChanges method immediately
            after
            initially loading it? After that, HasChanges may correctly reflect changes
            since loading.
            >
            Kerry Moorman
            >
            >
            "Al" wrote:
            >
            >Unfortunatel y HasChanges method returns True even right after populating
            >DataSet from XML file. I do not know why.
            >I also tried to populate another DataSet with GetChanges method. No
            >success
            >too - the resulting DataSet has rows in Tables. Do not know why either.
            >>
            >Al
            >>
            >>
            >"Kerry Moorman" <KerryMoorman@d iscussions.micr osoft.comwrote in message
            >news:290AE62 9-D4CB-44CC-AB16-0BCD87C21CB1@mi crosoft.com...
            Al,
            >
            The dataset has a HasChanges method that might work for you.
            >
            Kerry Moorman
            >
            >
            "Al" wrote:
            >
            >I'd like to know if there were any changes in the DataSet which was
            >populated by reading XML file. 6 DataTables with data or just
            >structure
            >with
            >no data inside of it.
            >I think about this scenario:
            >I create 2 datasets and populate both from the same XML file. Then the
            >first
            >one is used as DataSource for many controls and the second one is
            >untouched.
            >If there were some changes in the first one, I'd like to know it and
            >would
            >like to compare with the second one. I don't know how. Everything I
            >need
            >to
            >know is just were there any changes or not. If yes I will ask the user
            >if
            >he
            >wants to save them back into XML file.
            >>
            >So the question again: How do I compare 2 datasets? Or maybe somebody
            >can
            >suggest a better way to catch changes?
            >>
            >Thank you
            >Al
            >>
            >>
            >>
            >>
            >>
            >>

            Comment

            • Miha Markic [MVP C#]

              #7
              Re: Compare 2 DataSets


              "Al" <al@newsgroups. comwrote in message
              news:%23idoty1t GHA.2392@TK2MSF TNGP05.phx.gbl. ..
              >I cannot be sure yet, but I think with your help I found what is wrong. I
              >used to call AcceptChanges method every time I'm making changes in any
              >DataTable. I was thinking that this method will save my changes in the
              >DataSet only and without calling this method I will lose the changes I
              >make.
              I commented all AcceptChanges calls and now HasChanges seems to work
              properly.
              Yes, this is common misundestanding of what AcceptChanges really does. I
              guess the name is misleading...

              --
              Miha Markic [MVP C#, INETA Country Leader for Slovenia]
              RightHand .NET consulting & development www.rthand.com
              Blog: http://cs.rthand.com/blogs/blog_with_righthand/


              Comment

              Working...