The columns that I have in my DB are [CusName], [CusNo], [CusAdvance], [TotalAmount], [ID]
and [CusItem]
. I get the input of the name of the Customer to be deleted from textBox4.Text
.
I have modified the code as per what I got from you guys. But still the entries are not being deleted. They still remain inside the DB.
My Code:
void Button1Click(object sender, EventArgs e)
{
try
{
OleDbConnection delConn = new
OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=C:/NavneethCollection.accdb;Persist Security Info=False;");
delConn.Open();
String delQuery = "DELETE FROM NavColl WHERE [CusName]= @CustName";
OleDbCommand delcmd = new OleDbCommand();
delcmd.CommandText = delQuery;
delcmd.Connection = delConn;
delcmd.Parameters.AddWithValue("@CustName", textBox4.Text);
delcmd.ExecuteNonQuery();
MessageBox.Show("Customer has been successfully removed!");
}
catch(Exception exc)
{
MessageBox.Show("Error: "+exc.Message);
}
}