I get this error when I try to delete a row:
System.Data.OleDbException (0x80040E10): There was provided no value to one or more required parameters.
Here is my code:
C#
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:
- The database is not updated when i delete a record in the datagriedview.
- Don't let me delete the first line in datagriedview
Thanks in advance

Madhanmohan DevarajanRank #342 · 7.3K reputationPosted Oct 27, 2016, 8:07 AM EDT
Bikesh SrivastavaRank #108 · 20.3K reputationPosted Oct 27, 2016, 5:13 AM EDT
Md Ghouse40 reputationPosted Oct 27, 2016, 5:21 AM EDT
Madhanmohan DevarajanRank #342 · 7.3K reputationPosted Oct 27, 2016, 5:36 AM EDT
Satbr Brsat7 reputationPosted Oct 27, 2016, 7:56 AM EDT
Madhanmohan Devarajanthanks,
Roshan GuragainRank #3,873 · 383 reputationPosted Oct 27, 2016, 1:31 PM EDT
{
int selectedIndex = BooksGrid.SelectedRows[0].Index;
// gets the RowID from the first column in the grid
int rowID = int.Parse(BooksGrid[0, selectedIndex].Value.ToString());
string sql = "DELETE FROM Table1 WHERE RowID = @RowID";
// your code for deleting it from the database
// then your code for refreshing the DataGridView
}