title: Can't fix Concurrency Violation VB/Access Database
body: <p>Cannot figure out how to resolve this issue. If I add rows to the database and close the form and then open the form an remove rows, I get no issues. The issue only arises when I add rows and remove rows without closing the form. What happens when the form closes that doesn't happen when the form is open?</p>
  
  <p>If a box is checked, it gets added to the database. If a box gets unchecked it gets removed.</p>
  
  <p>Concurrency violation: the DeleteCommand affected 0 of the expected 1 records.</p>
  
  <p>Deleted row information cannot be accessed through the row.</p>
  
  <hr>
  
  <pre><code>Private Sub CreateNewDataRow(intNewTreeView As Integer, intNewUserID As Integer)
  
          Dim tvGeneric As Windows.Forms.TreeView
          Dim intTopic As Integer
  
          tvGeneric = GetTreeView(intNewTreeView)
          intTopic = intNewTreeView
  
          Try
              ' Loop through tabs to get checked items
              For x As Integer = 0 To tvGeneric.Nodes.Count - 1
                  If tvGeneric.Nodes(x).Checked = True Then
                      Dim drNewRow As MasterDBDataSet.DBAssignedRow
                      drNewRow = MasterDBDataSet.DBAssigned.NewDBAssignedRow
  
                      With drNewRow
                          .AssignedUser = intNewUserID
                          .AssignedTask = tvGeneric.Nodes(x).Tag
                          .AssignedTopic = intTopic
                          .AssignedCompleted = 0
                          .AssignedWorkCenter = m_intWorkCenter
                          .MergeID = Merge.RandomNumber()
                      End With
  
                      For Each Task As DataRow In MasterDBDataSet.DBTasks
                          If Task.Item("TaskTopic") = intTopic Then
                              If Task.Item("MergeID") = drNewRow.AssignedTask Then
                                  Try
                                      drNewRow.AssignedHours = CInt(Task.Item("TimePerTask"))
                                  Catch ex As Exception
  
                                  End Try
                              End If
                          End If
                      Next
  
                      If CheckExistingAssignments(intNewUserID, drNewRow.AssignedTopic, drNewRow.AssignedTask) Then
                          MasterDBDataSet.DBAssigned.Rows.Add(drNewRow)
                      End If
                      DbAssignedTableAdapter.Update(MasterDBDataSet.DBAssigned)
                  Else
                      ' If check box unchecked, remove from database
                      For Each OldAssigned As DataRow In MasterDBDataSet.DBAssigned
                          If OldAssigned.Item("AssignedTask") = tvGeneric.Nodes(x).Tag And OldAssigned.Item("AssignedUser") = intNewUserID Then
                              Try
                                  OldAssigned.Delete()
                              Catch ex As Exception
  
                              End Try
                              Exit For
                          End If
                      Next
                      DbAssignedTableAdapter.Update(MasterDBDataSet.DBAssigned)
                  End If
              Next
  
              DbAssignedTableAdapter.Update(MasterDBDataSet.DBAssigned)
          Catch ex As Exception
              Logger.WriteLog("ERROR : " &amp; ex.Message)
          End Try
  
      End Sub
  </code></pre>