0
votes

Why is this code not working?

        (this.namesBindingSource.Current as DataRowView).Delete();         
        this.namesTableAdapter.Update(database1DataSet1);

Error : Update requires a valid DeleteCommand when passed DataRow collection with deleted rows.

Database is service-based database added to project with only one table which is show in dataGridView and this code is linked to button. You will click on row for delete and then pres button and get error....

What is wrong? I'm getting crazy......

2
What is the value of namesTableAdapter.DeleteCommand property? - alex.b

2 Answers

2
votes

The error message is self explanatory. You need a valid DeleteCommand for namesTableAdapter. Otherwise it does not know you to delete your "deleted" rows. The same is true for Update or Insert-Commands.

Delete() just changes the RowState. If you use a DataAdapter (or TableAdapter) it needs to know what to do if the state is Deleted or Modified.

How to: Create TableAdapter Queries

0
votes

use CommandBuilder but remember you need to use table with a key column in it.