通过按钮单击从C#删除MS Access数据库中的数据

时间:2015-03-27 17:42:48

标签: c# database ms-access

我试图通过按钮点击从我的数据库中删除数据但是我当前收到错误:

"未处理的类型' System.Data.OleDb.OleDbException'发生在System.Data.dll

附加信息:没有给出一个或多个必需参数的值。"

这是我删除按钮的代码:

private void btnDelete_Click(object sender, EventArgs e)
    {
        connect.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\Foundation Degree\Year 2\Chris Ovia\Assignment2\Assignment2\BookSellersDatabase.mdb";
        tempTitle = txtTitle.Text;
        connect.Open();
        OleDbCommand cmd = new OleDbCommand("DELETE FROM Book WHERE Title = tempTitle", connect);
        cmd.ExecuteNonQuery();
        MessageBox.Show("Data Deleted", "Deleted", MessageBoxButtons.OK, MessageBoxIcon.Information);
        connect.Close();

        //this.Refresh();
        //Application.DoEvents(); 
    }

1 个答案:

答案 0 :(得分:2)

删除查询应为

OleDbCommand cmd = new OleDbCommand("DELETE FROM Book WHERE Title ='" +  tempTitle + "'", connect);