Concurrecy Error, anyone see what I'm doing wrong here ?

  • Thread starter Thread starter Terry Burns
  • Start date Start date
T

Terry Burns

This code takes the Person index drom the datagrid dgPeople and uses it to
delete all the records from the dgEvents grid and underlying records. It
works but i do get that concurrency message



Case "Delete"

Try

'open connection

con.Open()

'Setup the Delete Command for events for this person

DeleteCmd.CommandText = "DELETE * FROM [Events] WHERE PersonIndex = ?"

DeleteCmd.Connection = con

DeleteCmd.CommandType = CommandType.Text

DeleteCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_PersonIndex",
System.Data.OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"PersonIndex", System.Data.DataRowVersion.Original, Nothing))

Dim r As DataRow

PersonIndex = CType(dgPeople.Item(dgPeople.CurrentRowIndex, 0), Int32)

For Each r In tableEvents.Rows

If PersonIndex = CType(r.Item(0), Int32) Then

r.Delete()

End If

Next

daEvents.DeleteCommand = DeleteCmd

daEvents.Update(tableEvents)

Catch ex As OleDbException

MessageBox.Show(ex.Message)

Finally

con.Close()

End Try
 
Grid, DataAdapter, Access Source

What is the best way to delete multiple rows bound to a datagrid without
getting a concurrency exception.

TIA


Terry Burns said:
New data, this does not happen if there is only one row to delete. Any ideas
appreciated


Terry Burns said:
This code takes the Person index drom the datagrid dgPeople and uses it to
delete all the records from the dgEvents grid and underlying records. It
works but i do get that concurrency message



Case "Delete"

Try

'open connection

con.Open()

'Setup the Delete Command for events for this person

DeleteCmd.CommandText = "DELETE * FROM [Events] WHERE PersonIndex = ?"

DeleteCmd.Connection = con

DeleteCmd.CommandType = CommandType.Text

DeleteCmd.Parameters.Add(New
System.Data.OleDb.OleDbParameter("Original_PersonIndex",
System.Data.OleDb.OleDbType.Integer, 0,
System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte),
"PersonIndex", System.Data.DataRowVersion.Original, Nothing))

Dim r As DataRow

PersonIndex = CType(dgPeople.Item(dgPeople.CurrentRowIndex, 0), Int32)

For Each r In tableEvents.Rows

If PersonIndex = CType(r.Item(0), Int32) Then

r.Delete()

End If

Next

daEvents.DeleteCommand = DeleteCmd

daEvents.Update(tableEvents)

Catch ex As OleDbException

MessageBox.Show(ex.Message)

Finally

con.Close()

End Try
 
Back
Top