Compare 2 DataSets

A

Al

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
 
A

Al

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
 
G

Guest

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
 
A

Al

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

Al
 
A

Al

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
 
M

Miha Markic [MVP C#]

Al said:
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...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top