[英]Deleting a record in a database table
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. 每当我单击它时,它就会在消息框中显示Microsoft Access数据库引擎 ,但不会删除该记录。
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.