Help make sure that when you click on the button, the selected line in the DataGridView is deleted from the database

I found an answer on the Internet, but this function does not remove the selected value from the database, and when the table is updated, they reappear

private void button4_Click(object sender, EventArgs e) { foreach (DataGridViewRow item in this.dataGridView1.SelectedRows) { dataGridView1.Rows.RemoveAt(item.Index); } } 

Here's how the data is connected to the DataGridView

 private void button1_Click(object sender, EventArgs e) { con.Open(); OracleDataAdapter oda = new OracleDataAdapter("select *from nebera_stadion", con); DataTable dt = new DataTable(); oda.Fill(dt); dataGridView1.DataSource = dt; dataGridView1.Columns["id_stadion"].Visible = false; con.Close(); } 
  • Hindus have done a huge bunch of lessons on this topic youtu.be/mdFgbdM8PYk or youtu.be/cQQy_IfFddg Although, I wouldn’t recommend writing to you like that, well, I don’t need to use the DataSet , DataAdapter , DataTable from ADO.Net. you need to create an application model from the classes, and for binding use the BindingSource . - Bulson
  • How does the data get into the datagridview? Is data binding used? What is the source of the data: collection of objects, DataTable or what? How do you work with the database: raw ADO.NET, micro-ORM type Dapper, ORM type EF? - Alexander Petrov
  • I indicated as what is the source of the data - TroyyBoi_
  • I need that I can delete the row that is selected in the DataGridView from the database so that when updating the database they do not appear there again - TroyyBoi_
  • Well, since you are using a DataAdapter , you need to call its Update method. In this case, the properties UpdateCommand , DeleteCommand must be set. - Alexander Petrov

1 answer 1

 delete * from table where id = 34