Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,
Dear memebers, when I'm trying to delete and update my bindingnavigator it shows me following error.
Update requires a valid DeleteCommand when passed DataRow collection with deleted rows.
I dont whats going wrong following is the code to update my binding navigator
VB
Me.Validate()
Me.TableAdapterManager.UpdateAll(Me.myDataSet)
Me.myBindingSource.EndEdit()

Plz i need ur help...
Posted
Updated 27-Sep-17 4:26am
v2

You have not mentioned your delete command. In the properties of the adapter object check the delete command field.
If there is no primary key for this table then you can not delete or update.
 
Share this answer
 
v2
Try checking the properties of the TableAdapterManager update & delete commands to see if they are valid.

If the table being affected has no primary key this can also cause this type of problem.

Reference[^]
 
Share this answer
 
Try putting your EndEdit line before you do the update.

If that doesn't work, you can try the old method. I've never seen this fail. I use it after the UpdateAll(Me.myDataSet) to check if it really updated.
It's extraneous, and should be unnecessary, but it works.
Just change the Dataset names and TableAdapter names. You might even want to put them in a Try Catch
VB
If yourDataSet.HasChanges then
  'Don't forget the '()' since DataRow is an array
  dim drModified() as DataRow = yourDataSet.Table.Select("", "", _ 
      DatViewRowState.ModifiedCurrent)
  If drModified.Count > 0 then
     yourTableAdapter.Update(drModified)     'Not TableAdapterManager
  End If

  Dim drDeleted() As DataRow = yourDataSet.Table.Select("", "", _
      DataViewRowState.Deleted)
  If drDeleted.Count > 0 Then
     Me.yourTableAdapter.Update(drDeleted)
  End IF

  Dim drAdded() As DataRow = yourDataSet.Table.Select("", "", _
      DataViewRowState.Added)
  If drAdded.Count > 0 Then
      yourTableAdapter.Update(drAdded)
  End If
End If

'You can also combine the above into one line as below.
Dim drModified() As DataRow = yourDataSet.Table.Select("", "", _
     DataViewRowState.ModifiedCurrent Or DataViewRowState.Added)

'I would keep the Deleted line separate so you can confirm all deletes and cancel if you want.
 
Share this answer
 
v3
Comments
Richard Deeming 27-Sep-17 11:42am    
This question was asked and answered SIX YEARS AGO.

And your solution doesn't address the problem described in the question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900