Click here to Skip to main content
15,917,971 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am developing an application in C # with access to a database created in MS Access 2007. I have a WindowsForm to delete records from the database, but I'm only able to delete rows in the datagriedview (except the first) and the database is not being updated.

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.

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,

What I have tried:

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();
           }


        }
Posted

1 solution

You could delete the selected row(s) from the database, THEN re-fetch the data, and refresh the gridview...
 
Share this answer
 
Comments
Member 12801143 27-Oct-16 16:36pm    
not working!!!!!
Member 12801143 27-Oct-16 16:37pm    
and how i update the database??

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900