[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 158
  • Last Modified:

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
0
djoyceRRD
Asked:
djoyceRRD
  • 6
  • 6
1 Solution
 
Kyle AbrahamsSenior .Net DeveloperCommented:
why are you ignoring the 1-2 change?
0
 
djoyceRRDAuthor Commented:
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.
0
 
Kyle AbrahamsSenior .Net DeveloperCommented:
Confused . . . why isn't the 2-2 change also applied to the DB at the same time 1-2 is applied?  
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
djoyceRRDAuthor Commented:
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.  
0
 
Kyle AbrahamsSenior .Net DeveloperCommented:
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?
0
 
djoyceRRDAuthor Commented:
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.
0
 
Kyle AbrahamsSenior .Net DeveloperCommented:
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?

0
 
djoyceRRDAuthor Commented:
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.
0
 
djoyceRRDAuthor Commented:
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.
0
 
Kyle AbrahamsSenior .Net DeveloperCommented:
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.
0
 
djoyceRRDAuthor Commented:
How do I update the dataset?
0
 
Kyle AbrahamsSenior .Net DeveloperCommented:
dim dt as Datatable = dsChange("TableName")
dim row = dt.NewRow()

row = dsChange.Select("job =" & strMyJob)
row(0)("Column") = 'dsMain Value

Repeat for all Columns.  I'm assuming only 1 row is returned.  If you can get more than 1 row for a job then you would do:
for each r as DataRow in dsChange.Select("job =" & strMyJob)
r("column") = 'dsMain Value
next
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

  • 6
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now