3

im working on updating information in mic access 2010 using this code, but its keep telling me the syntax error in update statement. ihd already search through the previous answers but non of them work. here is my snipped code. tell me if you guys need more information.

try
{
    OleDbCommand renew = test.CreateCommand();
    renew.CommandType = CommandType.Text;
    renew.CommandText ="UPDATE Energy_Audit SET Appliances = @app, Usage Per Day = @usg, Power (Watt) = @pow, Number of Item = @num Where ID = @id )";
    renew.Parameters.AddWithValue("@app", txtApp.Text);
    renew.Parameters.AddWithValue("@usg", txtUsg.Text);
    renew.Parameters.AddWithValue("@pow", txtPwr.Text);
    renew.Parameters.AddWithValue("@num", txtNum.Text);
    renew.Parameters.AddWithValue("@id", txtID.Text);
    renew.ExecuteNonQuery();
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message);
}
1
  • you would need to enclose in brackets like [Usage Per Day] Commented Jul 17, 2013 at 9:13

2 Answers 2

1

You cannot have space in column name, so do this, put [] around it :

UPDATE Energy_Audit SET Appliances = @app, [Usage Per Day] = @usg, [Power (Watt)] = @pow, [Number of Item] = @num Where ID = @id 
Sign up to request clarification or add additional context in comments.

2 Comments

thank you!!. that solve the syntax problem. but then i got the extra ")" error. i removed it. then i run the program again but when i clicked update button it not updating the data T.T . any idea?
It should work, make sure your id is found in the table. and that the updated values are not the same
0

Change your query like this:

UPDATE Energy_Audit
SET Appliances = @app, [Usage Per Day] = @usg, [Power (Watt)] = @pow, [Number of Item] = @num
Where ID = @id )

if your column name contains spaces it has to be encapsulated in square brackets.

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.