private void btn_remover_Click(object sender, EventArgs e) { using (OleDbConnection oleConn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Stock_Material.accdb")) { try { oleConn.Open(); if (MessageBox.Show("Tem a certeza que pretende remover este registo(s)", " Confirmação", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == System.Windows.Forms.DialogResult.Yes) foreach (DataGridViewRow row in dataGridView_remover.SelectedRows) { int rowId = Convert.ToInt32(row.Cells[0].Value); if (rowId > 0) { dataGridView_remover.Rows.RemoveAt(row.Index); OleDbCommand delcmd = new OleDbCommand("Delete from product where id_Produto= " + rowId + ""); delcmd.Connection = oleConn; delcmd.ExecuteNonQuery(); } } } catch (Exception ex ) { MessageBox.Show(ex.ToString()); } oleConn.Close(); } }
How can I solve these problems:
Thanks in advance