djoyceRRD
asked on
How do I update certain rows in a dataset and remerge into original?
I have 1 large dataset, where certain rows can 'match'. Users can modify any of the rows, but if they hit 'auto-match', I combine the matched rows, delete the extra row, then post to the database. Other rows that are linked to the matched row also get posted to the database. Then I want to combine everything back into 1 dataset.
Ex.
Job 1-1, Match = Y, modified = N
Job 1-2, Match = N, modified = Y
Job 2-1, match = N, modified = N
Job 2-2, match = N, modified = Y
* User hits 'automatch'
I pull all changed records into a dataset (dsChange - now contains Job 1-2 and 2-2), and set dsMain.ApplyChanges to clear all rowstates since I only want specific data updated
Job 1-1 is combined with it's match, and the match is deleted in dsMain
Job 1-2 is marked to be updated
Changes are posted to the db - dsMain.Update()
Now I want to reapply the change to Job 2-2, but ignore the change for 1-2, and have a final set of data in dsMain again. The final ds should only show 2-2 as modified.
Currently I am doing the below to have the Main ds take precidence over the changes.
dsChange.Merge(dsMain)
dsMain = dsChange
The problem is that since 1-2 is marked as changed in dsChange, and not changed in dsMain, the final dsMain shows that 1-2 is still changed. There is a timestamp that is updated, so I can tell if the row was updated in the auto-match.
I know this is confusing, please let me know where I need to clarify.
Thanks,
Denise
Ex.
Job 1-1, Match = Y, modified = N
Job 1-2, Match = N, modified = Y
Job 2-1, match = N, modified = N
Job 2-2, match = N, modified = Y
* User hits 'automatch'
I pull all changed records into a dataset (dsChange - now contains Job 1-2 and 2-2), and set dsMain.ApplyChanges to clear all rowstates since I only want specific data updated
Job 1-1 is combined with it's match, and the match is deleted in dsMain
Job 1-2 is marked to be updated
Changes are posted to the db - dsMain.Update()
Now I want to reapply the change to Job 2-2, but ignore the change for 1-2, and have a final set of data in dsMain again. The final ds should only show 2-2 as modified.
Currently I am doing the below to have the Main ds take precidence over the changes.
dsChange.Merge(dsMain)
dsMain = dsChange
The problem is that since 1-2 is marked as changed in dsChange, and not changed in dsMain, the final dsMain shows that 1-2 is still changed. There is a timestamp that is updated, so I can tell if the row was updated in the auto-match.
I know this is confusing, please let me know where I need to clarify.
Thanks,
Denise
why are you ignoring the 1-2 change?
ASKER
Because it was already processed along with the matched records. There can be multiple parts to a job, but not all have to have matches. All parts of the job must be processed at the same time.
Confused . . . why isn't the 2-2 change also applied to the DB at the same time 1-2 is applied?
ASKER
Because 2-1 and 2-2 do not have a 'match'. Sorry, I know this is an odd situation. What it is doing is processing all records that have a match (an automatically created record with a manually created one). Since all parts of a job need to be processed at the same time, any record associated w/ the job that has a match must be processed. Where it gets tricky, is that users can make changes to any record before/after the auto-match. Those changes shouldn't be lost for the jobs that aren't part of the auto-match.
I think I might have found a different way to handle the merging of the 2 datasets. Since there shouldn't be many changes (dsChange), I am reading through one by one after the db update and finding the same record in dsMain. If the timestamp is the same (meaning it wasn't updated to the db), then merge the row from dsChange into dsMain.
I think I might have found a different way to handle the merging of the 2 datasets. Since there shouldn't be many changes (dsChange), I am reading through one by one after the db update and finding the same record in dsMain. If the timestamp is the same (meaning it wasn't updated to the db), then merge the row from dsChange into dsMain.
but the automatch shouldn't write to the database.
You should process all changes locally in the dataset, then write once to the DB.
My question is about 1-2 and 2-2 . . . why is it okay to process 1-2 (no match) but not 2-2 (no match)? How does that happen that 2-2's changes are written?
You should process all changes locally in the dataset, then write once to the DB.
My question is about 1-2 and 2-2 . . . why is it okay to process 1-2 (no match) but not 2-2 (no match)? How does that happen that 2-2's changes are written?
ASKER
The automatch writes to the dataset first, then uses ADO to write to the database. 1-2 is processed with the automatch because 1-1 has a match - all parts of the job must be processed at the same time. 2-2 is not included because neither it nor 2-1 have a match. There is a separate button to save other changes. I have to write the changes to the db in the automatch because I cannot be sure the user will actually save the other changes.
so 1-1 and 1-2 are related.
Once you update the DB . . . 1-2 should no longer be modified in the main table. Can't you assign dsChanges = dsMain after you do the automatch?
Once you update the DB . . . 1-2 should no longer be modified in the main table. Can't you assign dsChanges = dsMain after you do the automatch?
ASKER
Yes, sorry, 1-1 and 1-2 are part of the same job (1), and 2-1 and 2-2 are the same job (2).
By assigning dsChange = dsMain, I would lose the change to 2-2, which was not updated as part of the automatch. In the example above, dsChange would contain 1-2 and 2-2. In my final ds, I only want 2-2 to have a status of modified.
By assigning dsChange = dsMain, I would lose the change to 2-2, which was not updated as part of the automatch. In the example above, dsChange would contain 1-2 and 2-2. In my final ds, I only want 2-2 to have a status of modified.
ASKER
Yes, sorry, 1-1 and 1-2 are part of the same job (1), and 2-1 and 2-2 are the same job (2).
By assigning dsChange = dsMain, I would lose the change to 2-2, which was not updated as part of the automatch. In the example above, dsChange would contain 1-2 and 2-2. In my final ds, I only want 2-2 to have a status of modified.
By assigning dsChange = dsMain, I would lose the change to 2-2, which was not updated as part of the automatch. In the example above, dsChange would contain 1-2 and 2-2. In my final ds, I only want 2-2 to have a status of modified.
When updating the DB also run it against the other DataTable in the Set.
(EG: do update in DB and in dsChange).
That should leave you with only unmatched changes in dsChange.
(EG: do update in DB and in dsChange).
That should leave you with only unmatched changes in dsChange.
ASKER
How do I update the dataset?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.