Comparing 2 datasets...

F

Frank

Hello,

Developing an app where the user fills out a sometimes quite lengthy
form of chkboxes, txtboxes, radbtns, etc. User responses are saved to
a mySql db, which the user can later edit.
When the user chooses to edit, I pull the responses from the db, toss
them in a dataset, check the checks, fill the txtboxes, etc.,etc.
The user then adds, deletes, or changes entries as needed and clicks
the Save Changes button. Here is where the fun begins....
I have to keep track of changes made to the saved form and mark those
items that have 'changed' as well as inserting the new editions to the
database.

My logic so far is this: When they click the Save Changes btn, I throw
all the responses into a new dataset and then compare the original
dataset to the new dataset.
Basically, if an anwer exits in dataset 1 (the original), but not in
dataset 2, that anwer was changed. Conversely, if an answer exits in
dataset 2 (the edited version), but not in dataset1, that answer was
added.

My question is: How can I best compare the 2 datasets, see what has
changed and update the db accordingly, while being minfull that NO
entries can be deleted, only marked as changed or added.

Here is some code that I have tried (from my head):

for i = 0 to dataset1.tables(0).count -1
for j = 0 to dataset2.tables(0).count - 1
if dataset1.tabels(0).rows(i)(3).tostring =
dataset2.tabels(0).rows(j)(3).tostring 'Entry exists in both ds's
exit for
Else
Take action to mark as changed
end if
next
next

As of yet, this does not produce the results I am looking for, and I
can't figure it out. Something wrong with the loop??? I know this is
not very elegant, but if someone could suggest a better way, I am all
ears!!!! Maybe dataset1.Merge(dataset2)????

Thanks for the Help!!!!
(I apologize for the crossposting)

Frank
 
G

Guest

Frank
This is the exact same situation I am in. I have an app that lets the user
search for a specific record and then update just one of the corresponding
columns. With two buttons I can't access the original dataset through normal
coding. I've yet to find away around this except for the unsucessful
comparing of the 2 datasets. If you have any luck with yours let me know and
I'll do the same.
Thanks
 
F

Frank

Neo,

I will keep you posted on progress. At this point, my method works,
but only if the user changes more than 1 item. For some reason, it
fails if there is only 1 change. I think the route I am going to
attempt next is along the lines of what Cor suggested: Search for
matching datarows. Something like this:

dim dr as datarow
dim drChg as datarow
for each dr in dt1
drChg = Dt2.Rows.Find(dr.Item(Some Criteria))
If drChg Is Nothing Then
dt3t.Rows.Add(dr)
Else
...
End If
next
(Or something thereabouts...)
Will let you know how it works..
 
F

Frank

Cor,

Thanks for the help. Think I will take your very sage advice and try
something similar to what you suggest.

Thanks again!!
 

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