删除数据库表中的记录

时间:2018-06-28 04:46:12

标签: c# ms-access

在单击分配给删除记录的按钮时,我遇到了问题。每当我单击它时,它都会在消息框中显示 Microsoft Access数据库引擎,但它不会删除该记录。

这是我的代码:

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

1 个答案:

答案 0 :(得分:-1)

我已经弄清楚了,谢谢您的帮助!我将数据库命令更改为

overflow: hidden;