BindingNavigatorDeleteItem

K

kvenkatu

Hello,

I am trying to delete a row from a datagrid using BindingNavigator
delete iterm.
I added the following code in BindingNavigatorDeleteItem_Click().
This code only deletes the record from the datagrid, it does not delete
from the database table.

Private Sub BindingNavigatorDeleteItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
BindingNavigatorDeleteItem.Click
If MessageBox.Show("Are you sure?", "",
MessageBoxButtons.YesNo) =
Windows.Forms.DialogResult.Yes Then
ContactBindingSource.RemoveCurrent()
End If
End Sub

To save to the database table, I need to click on the save button
after deleting a row.
When I click on the save button I am getting "Update requires a valid
DeleteCommand when passed DataRow collection with deleted rows" error
message. I have the following in Saveitem_click:
Me.Validate()
Me.ContactBindingSource.EndEdit()
Me.ContactBindingSourceTableAdapter.Update(Me.DataSet1.Contact)

I would appreciate the help with this problem.
 
C

Cor Ligthert [MVP]

Kvenkatu,

There is something strange in my idea,

First,

You can never delete something from a complex datacontrol as the datagrid,
therefore you are always removing or deleting from the underlying list,
which is in your case a datatable. (Are you sure it is a datagrid because
your code looks very much about that what is used in DataGridView samples).

There is in AdoNet a hug difference between deleting and removing.

Deleting means mark the row to be removed from the database at an update and
removed after that or with an acceptchanges

Removing means to remove the row from the datatable and therefore not any
action will be taken when there is a dataadapter.update.

Now you mark it as deleted and than you remove it.

Therefore maybe is this a better solution for your problem.

http://www.vb-tips.com/dbpages.aspx?ID=82ee4145-632c-42a1-83b9-57ec163eaa17

I don't know if it helps for the update problem because I find that strange
that it even gives that message.
Maybe is it where you have said *no* to remove, but than the rows are
deleted, but than we have two problems.

I hope this helps,

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top