简体   繁体   中英

C# Update and Delete row table using tableAdapter, mdb access, dataGridView

I have a DataGridView, which loads data from mdb Access table
The grid only shows data (is readonly). I have a button for inserting new row, and now have to make two more buttons, one for update and one for delete

The following code works fine for inserting a new row

this.estacionamientoTableAdapter.Insert(tb1.Text, tb2.Text, tb3.Text, null, null);
this.dataGridView1.EndEdit();
this.estacionamientoTableAdapter.Fill(estacionarDataSet.Estacionamiento);
this.dataGridView1.Refresh();

Can anyone provide me a sample for editing data from selected row, and for deleting a selected row from the grid? Of course using tableAdapter, Dataset, etc.?

you need to populate the UpdateCommand and EditCommand for your table.

something along the lines of:

this.estacionamientoTableAdapter.Adapter.UpdateCommand = new System.Data.SqlClient.SqlCommand("update statement",this.connection);

Alternatively if you are useing autogenerated code that was generated from a table without a primary key and you have the possibility to do so - then add a primary key and re-generate your table adapter.

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