[RESOLVED] [VS2008] Concurrency
Quote:
DBConcurrencyException was unhandled.
Concurrency violation: the DeleteCommand affected 0 of the expected 1 records.
Above is the error message received when doing the following:
Using a binding source for the datagrid I populate textboxes for the row that is currently selected. The problem occurs when I modify one of these textboxes, then delete a different row, then save (in that order). The following are the two scripts used in this process, if you need more I'd be happy to supply them.
Delete Script:
Code:
Private Sub cmdMCDeleteRecord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdMCDeleteRecord.Click
Dim PK As Integer = CInt(Me.dgvMyCigars.CurrentRow.Cells("ID").Value)
Dim MCconnection As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\cdb.rmd;Persist Security Info=False;")
Dim MCcommand As New OleDb.OleDbCommand("DELETE * FROM CigarTable WHERE ID = @ID", MCconnection)
Try
If MsgBox("Are you sure you wish to delete the current cigar?", MsgBoxStyle.YesNo, "eHumidor - Delete Record Confirmation") = MsgBoxResult.Yes Then
Me.MCBind.EndEdit()
DirectCast(Me.MCBind.Current, DataRowView).Delete()
Me.MCBind.EndEdit()
MCcommand.Parameters.AddWithValue("@ID", PK)
MCconnection.Open()
'Open Connection
MCcommand.ExecuteNonQuery()
MCconnection.Close()
Appstatus = "Cigar Successfully Deleted!"
Status()
End If
Catch ex As Exception
Appstatus = "Error 004 - Cigar not deleted. Please submit bug report!"
Status()
MsgBox(ex.Message)
Finally
If MCconnection.State = ConnectionState.Open Then
MCconnection.Close()
End If
End Try
End Sub
Save Script:
Code:
Try
Dim MCCmdBldr As OleDbCommandBuilder
Me.MCBind.EndEdit()
MCCmdBldr = New OleDbCommandBuilder(Me.MCadapter)
Debug.WriteLine(MCCmdBldr.GetUpdateCommand.CommandText())
Me.MCadapter.Update(Me.MCDS, "CigarTable")
Me.MCconnection.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
I've read MSDN on concurrency errors and while I can make sense of what concurrency is, I cannot see why I'm having this problem.