Hello all
I have a DataGrid1 presenting records of a table ("clients") in a Access
Database through a DataSet (ds) using DataAdapter (da1) and buttons "add",
"save" and"delete" buttons with the code bellow:
------------------
a button "Add":
Private Sub Button_Add_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button_Add.Click
Me.BindingContext(ds, "Clients").AddNew()
a button "Save":
---------
Private Sub Button_Save_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button_Save.Click
Me.BindingContext(ds, "Clients").EndCurrentEdit()
da1.Update(ds, "Clients")
-------
a button "Delete":
Private Sub Button_Delete_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button_Delete.Click
If MsgBoxResult.Yes = _
MessageBox.Show(" Do you really want to delete this item", "Confirm dialog
box", MessageBoxButtons.YesNoCancel) Then
Dim pos As Integer
pos = Me.BindingContext(DataGrid1.DataSource, "Clients").Position()
Me.BindingContext(DataGrid1.DataSource, "Clients").RemoveAt(pos)
da1.Update(ds, "Clients")
End If
---------------------------------------------------------------
You can see that, I already used function da1.Update(ds, "Clients") after
"Save". However, when I add new record, save that record and then click
"delete" to delete this record, there is error " Concurrency violation: the
DeleteCommand affected 0 records."
When I exit the application then run again, I can delete that record. I do
not know why. Could you please help
Thank you
SHoa