dbConcurrencyException
-
13 สิงหาคม 2555 13:56
Inoder for my code to allow me to save new record I set acceptchangesduringupdate to false but now lets say soon afrter I save I then delete a row and the save I get the error "Concurrency violation: the DeleteCommand affected 0 of the expected 1 records."dbConcurrencyException. What can I do?
Dim myConn As OleDbConnection = frmLogIn.Conn Dim oledbCmdBuilder As OleDbCommandBuilder Dim changes As DataTable Dim sql As String = "select * from ProductRawMaterial" Dim oledbAdapter As OleDbDataAdapter = New OleDbDataAdapter(sql, myConn) 'Try oledbCmdBuilder = New OleDbCommandBuilder(oledbAdapter) changes = myTable.GetChanges() oledbCmdBuilder.ConflictOption = ConflictOption.OverwriteChanges If changes IsNot Nothing Then oledbAdapter.AcceptChangesDuringUpdate = False oledbAdapter.Update(myTable) End If myConn.Close() '*************************************************************************************************************************************************** '********************************************************* SAVING TO AUDIT **************************************************************** Dim myKonn As OleDbConnection = frmLogIn.Connn Dim oledbCmdBuilderAudit As OleDbCommandBuilder Dim sqlAudit As String = "select * from ProductRawMaterial" Dim oledbAdapterAudit As OleDbDataAdapter = New OleDbDataAdapter(sqlAudit, myKonn) oledbCmdBuilderAudit = New OleDbCommandBuilder(oledbAdapterAudit) oledbCmdBuilderAudit.ConflictOption = ConflictOption.OverwriteChanges If changes IsNot Nothing Then oledbAdapterAudit.Update(myTable) End If myTable.AcceptChanges() myKonn.Close()
If you think it you can achieve it
- แก้ไขโดย tendaimare 13 สิงหาคม 2555 14:39
ตอบทั้งหมด
-
14 สิงหาคม 2555 6:41ผู้ดูแล
Hi tendaimare,
Welcome to the MSDN forum.
The exception means can’t find the row need to be deleted.
Does this exception only occur when you add a record, save it and delete the new record immediately?
If yes, it is because when you add a new record to database, you failed to add the auto number value in database to the dataset.
To solve this issue, you need to retrieve the assigned auto number and store it in the DataSet row after you update the new record into the database.
Hope this helps.
Mark Liu-lxf [MSFT]
MSDN Community Support | Feedback to us
- ทำเครื่องหมายเป็นคำตอบโดย Mark Liu-lxfModerator 22 สิงหาคม 2555 6:39
-
22 สิงหาคม 2555 6:39ผู้ดูแล
Hi tendaimare,
We haven’t heard from you for several days. I’d like to mark my reply as answer firstly. If you have any additional questions, you also can unmark the replay and post your question here.
Sorry for any inconvenience and have a nice day.
Mark Liu-lxf [MSFT]
MSDN Community Support | Feedback to us