我得到:DELETE FROM combobox.text數據庫
語法錯誤FROM子句;
cmdbox_Model.Text
正在顯示錶的名稱。
下面是代碼
我想直接從組合框中選擇表名。因此,用戶選擇一個模型類型,直接從該表中刪除。
string Product = cmdbox_Product1.Text;
string Model = cmdbox_Model.Text;
string MacID = txt_MAC_id.Text;
if (conn.State == ConnectionState.Open && (cmdbox_Product1.Text == "MODEM" && cmdbox_Model.Text == Model))
{
OleDbCommand cmd3 = new OleDbCommand("DELETE FROM " + cmdbox_Model.Text + "WHERE MacID = @MacID", conn);
cmd3.Parameters.AddWithValue("@MacID", MacID);
try
{
DialogResult result = MessageBox.Show("Are You Sure you Want to Delete this \""+ cmdbox_Product1.Text + "\"?", "Confirm DELETE",MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (result == DialogResult.Yes)
{
cmd3.ExecuteNonQuery();
MessageBox.Show("Successful Deleted", "", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
}
else MessageBox.Show("Failed To Delete", "", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); }
conn.Close();
}
catch (OleDbException expe)
{
MessageBox.Show(expe.Message);
MessageBox.Show("Error Failed to delete", "", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
conn.Close();
}
在'WHERE MacID = @ MacID'之前加一個空格' –
1.在where子句前加一個空格2.使用參數以避免SQL注入漏洞 – paqogomez
調制解調器模型的名稱是什麼?它是否包含空格? – Steve