Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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);
}
share|improve this question
you would need to enclose in brackets like [Usage Per Day] – V4Vendetta 6 hours ago

2 Answers

up vote 0 down vote accepted

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 
share|improve this answer
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? – user2590623 6 hours ago
It should work, make sure your id is found in the table. and that the updated values are not the same – Sam 6 hours ago
ty2!!! im trying to find this solution for weeks! – user2590623 6 hours ago

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.