0

I have a datagridview thats bounded to a db and bindingNavigator that has Add/Delete/Save buttons. When I select a row and delete it, the row gets deleted from the datagridview, but when I restart the application, it doesn't get physically deleted from the database. Search suggests putting this code inside the save button and press it before closing the application:

this.Validate();
        this.itemsBindingSource.EndEdit();
        this.itemsTableAdapter.Update(this.myDatabaseDataSet.Items);

        MessageBox.Show("Update successful");

But the database still have the row undeleted.

And using itemTableAdapter.Delete() method isn't really helpful since I've more than 30 columns in the table.

Any help?.

2
Contributors
3
Replies
14
Views
7 Years
Discussion Span
Last Post by Yamazaki
Featured Replies
  • If you are using tableadapters, i would recommend adding your own delete query. The standard ones are pretty heavy going, you have to put the value for every single column. If you add a new query to the table adapter along the lines of: [CODE=SQL] DELETE FROM [TableName] WHERE ([PrimaryKeyColumn] … Read More

1

If you are using tableadapters, i would recommend adding your own delete query. The standard ones are pretty heavy going, you have to put the value for every single column.

If you add a new query to the table adapter along the lines of:

DELETE FROM [TableName] WHERE ([PrimaryKeyColumn] = @Key)

You can call it like

itemTableAdapter.DelteQuery('keyvalue');

Edited by Geekitygeek: n/a

0

If you are using tableadapters, i would recommend adding your own delete query. The standard ones are pretty heavy going, you have to put the value for every single column.

If you add a new query to the table adapter along the lines of:

DELETE FROM [TableName] WHERE ([PrimaryKeyColumn] = @Key)

You can call it like

itemTableAdapter.DelteQuery('keyvalue');

Thanks but I get 'Error parsing query text' and .DelQuery(); doesn't accept 1 parameter 'Keyvalue', but I've to put in all 30+ columns values!!

Please take a look at this sample solution. You should notice add/del/save buttons have no affects on the db.

0

Alright I found a solution, the code should be:

this.Validate();
            this.itemsBindingSource.EndEdit();
            this.itemsTableAdapter.Update(myDatabaseDataSet.Items);
            this.myDatabaseDataSet.AcceptChanges();
            MessageBox.Show("Update successful");

And the db in bin\dir\"dbname" gets updated. Thanks for the help.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.