Difference between revisions of "Updating DataTable"
From RayHarwood
Rayharwood (Talk | contribs) (Created page with "Often necessary to update data base tables indirectly through the table-adapter based data table objects. You want to queue up changes (adds, modifications, deletions) in you...") |
Rayharwood (Talk | contribs) |
||
| Line 24: | Line 24: | ||
Dim ChangesMade As Integer = RuleItem_TA.Update(RuleItem_DT) | Dim ChangesMade As Integer = RuleItem_TA.Update(RuleItem_DT) | ||
| + | |||
| + | Before doing the update, you can check the status of the each record, as follows: | ||
| + | |||
| + | For Each Acct_Rec As ITSec_DataSet.ID_AccountsRow In Acct_DT.Rows | ||
| + | tspbProgressBar.Increment(1) | ||
| + | ' Add to counters, based on RowState of the record | ||
| + | Select Case Acct_Rec.RowState | ||
| + | Case DataRowState.Added | ||
| + | ' This is a NEW record in the table | ||
| + | RcdCount_Added += 1 | ||
| + | LogAction("New: " & Acct_Rec.AccountName) | ||
| + | Case DataRowState.Modified | ||
| + | ' This record EXISTED in the table and was UPDATED, so it was also in the import table | ||
| + | RcdCount_Modified += 1 | ||
| + | Case DataRowState.Unchanged | ||
| + | ' This record EXISTED in the table and was UNCHANGED, because it was NOT in the import table | ||
| + | If LCase(Trim(Acct_Rec.Status)) = "active" Then | ||
| + | RcdCount_Unchanged += 1 | ||
| + | LogAction("Missing: " & Acct_Rec.AccountName) | ||
| + | Else | ||
| + | RcdCount_Inactive += 1 | ||
| + | End If | ||
| + | Case Else | ||
| + | ' This state should not exist in this process: | ||
| + | RcdCount_Other += 1 | ||
| + | LogAction("Unknown: " & Acct_Rec.AccountName & " (" & Acct_Rec.RowState & ")") | ||
| + | End Select | ||
| + | Next | ||