0

Making a CRUD for an scholar library, while I can upload info I can't delete

Working with an ms Access .mdb

Tried this, which is similar to the one I use for looking for reading and showing info from the DB

   string consulta;
   OleDbConnection conexion;
   OleDbDataAdapter adaptador;
   DataSet ds = new DataSet();
   conexion = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Leona.mdb");

   consulta = "Delete from Libros where id=" + textBox4.Text;
   adaptador = new OleDbDataAdapter(consulta, conexion);

   adaptador.Fill(ds, "Libros");
   dataGridView2.DataSource = ds.Tables["Libros"];

Shows no error and deletes the book from the DataGridView but not from the DB, so I tried with ExecuteNonQuery which I used to add info to the DB and works

   string t = "Delete from Libros where id=" + textBox4.Text;

   OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Leona.mdb");
   OleDbCommand cmd = new OleDbCommand(t, conn);
   conn.Open();
   cmd.CommandText = t;
   cmd.ExecuteNonQuery();
   conn.Close();

Both output the same result, they delete from the app but the DB remains intact.

  • 2
    What does `cmd.ExecuteNonQuery()` return? Also, you need to [use parameters](https://stackoverflow.com/questions/7505808/) before someone types in an ID of `0 OR 1=1`. – Dour High Arch Nov 05 '19 at 19:20
  • How do you verify that the database is unchanged? If its gone from the app....? If you are using another application to verify the database records, then perhaps you are not looking at the correct database. – Sam Axe Nov 05 '19 at 19:31

0 Answers0