0

removebutton_Click

protected void removebutton_Click(object sender, EventArgs e)
{
    string RemoveSQL;

    OleDbConnection mDB = new OleDbConnection();
    mDB.ConnectionString = "Provider = Microsoft.ACE.OLEDB.12.0;Data source="
                           + Server.MapPath("~/App_Data/database.accdb");
    mDB.Open(); OleDbCommand cmd;

    Button removebutton = (Button)sender;
    Label carttransactionlabel = (Label)removebutton.Parent.FindControl("carttransactionlabel");

    int intTransNo = int.Parse(carttransactionlabel.Text);

    RemoveSQL = "DELETE FROM orderItems"
                + "WHERE iTransaction_No = @TransNo";

    cmd = new OleDbCommand(RemoveSQL, mDB);

    cmd.Parameters.Add("@TransNo", OleDbType.Integer).Value = intTransNo;

    cmd.ExecuteNonQuery();

    mDB.Close();
}

What I am trying to accomplish here is that when the user clicks on the removebutton button, the SQL command RemoveSQL will remove the entire row of transaction from the orderItems table in MS Access based on the transaction number (carttransactionlabel).

Table enter image description here

However, when I try to click on the removebutton button, this error appears enter image description here

Apparently there's a syntax error in the SQL statement which I can't seem to spot. Help would be appreciated.

1
  • 6
    Missing a space between orderItems and WHERE Commented Jan 7, 2017 at 17:01

1 Answer 1

2

Print out your SQL before running it! At least some problems will be obvious.

You have this code:

RemoveSQL = "DELETE FROM orderItems" + "WHERE iTransaction_No = @TransNo";

If you print this out, it will look like:

RemoveSQL = "DELETE FROM orderItemsWHERE iTransaction_No = @TransNo";

The error and fix should be obvious.

Note: You may have other issues in your code.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.