简体   繁体   中英

DataGridview won't update/delete

I'm using an access database in a C# project. I also have a DataGridView to display and edit the table. It works fine when I'm adding a new line but I get an exception when deleting/editting an existing line.
Update requires a valid DeleteCommand when passed DataRow collection with deleted rows.
the relavent Code:

private void updateB_Click(object sender, EventArgs e)
{
    this.complaintsTableAdapter.Update(this.databaseDataSet.complaints);
    this.complaintsTableAdapter.Fill(this.databaseDataSet.complaints);

}  

you must set some settings in complaintsTableAdapter
in TableAdpater set Insert , Update , Delete Command or if you create table adapter automatically from designer can use
Create method to send updates directly to the database (GenerateDBDirectMethods)

this can fix your problem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM