简体   繁体   中英

DELETE FROM combobox.text database

I get :

SYNTAX ERROR IN FROM Clause;

cmdbox_Model.Text is displaying the name of the table.

Here is the code

I want to select the table name directly from the combo-box. So went the user select a model type it be directly deleted from that table.

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

You are missing the space between table name and WHERE.

Try This:

OleDbCommand cmd3 = new OleDbCommand("DELETE FROM " + cmdbox_Model.Text + " WHERE MacID=@MacID", conn);

Where have you include the table name in the query?

"DELETE FROM " + cmdbox_Model.Text + "WHERE MacID=@MacID"

You haven't mentioned the Table name.

This

DELETE 
FROM TABLE NAME
WHERE 

is how you write the query.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM