0

Using C#, I had a problem with a database I use directly in Access. I used an OleDbDataAdapter, OleDbCommandBuilder and DataTable. The update command was generated by the OleDbCommandBuilder. Using this update command would generate a syntax error in the UPDATE statement.

As a test, I created a real simple Access database with 2 fields: Name and Job. Using the exact code from what I described above (except for obvious changes), the update command worked fine with this. Then I created another database with 5 fields: Name, Job, Id, Year and Country but this got the same syntax error as above. I commented out different field assignments until I found that it is the "Year" field that will causes the error. The Id and Year fields are both integers and the others are text. It will update the Id field and text fields, but if I include the Year field it will generate the error. It makes no sense!

Can any one make sense of this and help please??? Is there a way to see the SQL update expression that the OleDbCommandBuilder is using?

Thanks!

Valhalla

1
  • Can you please post the code that you are having an issue with? Commented Oct 9, 2014 at 23:17

2 Answers 2

2

'Year' is a reserved word in MS Access DB, see http://support.microsoft.com/kb/286335 . You can rename field Year into something else like '_Year'.

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

Comments

0

You must put field names that correspond to reserved names in MS Access (like Year) in bracket (like this : [Year]).

9 Comments

Ahhhhhh.....relief alas!!!! :) lol Man...I guess I will have to stop and ask people for directions when driving too now.... Loool! I wasted so much time from overlooking something basic.... Arrggggggg! :) Thank you! Thank you ! Thank you!!!! This is probably the problem with the original database I was working with as I had field names like Type Length etc...... It's funny though that these names, including "Year" did not cause a problem when using this directly in Access... Yes brackets I forgot about that...Thanks to all of you that answered this!
This is what I get for getting our of programming for the last 8 years.
Oooops.....I was relieved too soon. I changed all the fields in the original db that were in question and ran the program with the changed version but it still gets a syntax error if I change even one text field. Here is the what it is showing in the error dialog box that pops up:
Syntax error (missing operator) in query expression '((MOVIE = ?) AND ((? = 1 AND Genre IS NULL) OR (Genre = ?)) AND ((? = 1 AND Box Name IS NULL) OR (Box Name = ?)) AND ((? = 1 AND _Type IS NULL) OR (_Type = ?)) AND ((? = 1 AND _LENGTH IS NULL) OR (_LENGTH = ?)) AND ((? = 1 AND Viewed IS NULL) OR (Viewed ='.
What are all the '?' you put in there ?
|

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.