开发者

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 inser开发者_如何学Cting 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜