I got problem when it comes to clicking the button assigned for deleting the record. Whenever I click it, it shows the Microsoft Access Database Engine in the message box but it doesn't delete the record.
Here is my code:
private void button1_Click(object sender, EventArgs e) {
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = (@ "Provider= Microsoft.ACE.OLEDB.12.0;Data Source =C:\Users\pc\Documents\Visual Studio 2015\Projects\GamefarmDB\GamefarmDB\Gamefarm.accdb;User ID = admin;Jet OLEDB:Database Password=admin; Persist Security Info=True;");
String WingbandNumber = textBox1.Text;
OleDbCommand cmd = new OleDbCommand("DELETE FROM List WHERE WingbandNumber ='" + WingbandNumber + "'", conn);
conn.Open();
if (conn.State == ConnectionState.Open) {
cmd.Parameters.Add("@WingbandNumber", OleDbType.Numeric).Value = WingbandNumber;
try {
cmd.ExecuteNonQuery();
MessageBox.Show("Data Deleted");
conn.Close();
this.Close();
} catch (OleDbException ex) {
MessageBox.Show(ex.Source);
conn.Close();
}
} else {
MessageBox.Show("Connection Failed");
}
}
I've figured it out anyways thank you for your help! I changed the database command into
("DELETE FROM List WHERE WingbandNumber =" + WingbandNumber, conn);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.