question

RezaJaferi1992 avatar image
0 Votes"
RezaJaferi1992 asked RezaJaferi1992 published

This error ('Syntax error in INSERT INTO statement') is displayed while my Query is correct

First and foremost, I apologize for my grammatical errors; my first language is Persian (Iran).
This error ('Syntax error in INSERT INTO statement') is displayed while my Query is correct but i solved the problem- and i just want to know the cause of this problem?

 OleDbCommand OleDbCommand_Insert = new OleDbCommand("Insert Into [BookTable](BookName,Publisher,Category,BookCode,Stock,HistoryTaken,RecipientName,ReturnDate,ReleaseDate,Language,Length,Form,Translator,Narrator,ISBN,Location,BookImage)values('" + BookName_TextBox.Text.Trim() + "','" + Publisher_TextBox.Text.Trim() + "','" + Category_ComboBox.Text.Trim() + "','" + BookCode_TextBox.Text.Trim() + "','" + Stock_ComboBox.Text.Trim() + "','" + HistoryTaken_TextBox.Text.Trim() + "','" + RecipientName_TextBox.Text.Trim() + "','" + ReturnDate_TextBox.Text.Trim() + "','" + ReleaseDate_TextBox.Text.Trim() + "','" + Language_TextBox.Text.Trim() + "','" + Length_TextBox.Text.Trim() + "','" + Form_ComboBox.Text.Trim() + "','" + Translator_TextBox.Text.Trim() + "','" + Narrator_TextBox.Text.Trim() + "','" + ISBN_TextBox.Text.Trim() + "','" + Location_TextBox.Text.Trim() + "',@Image)", OleDbConnect);

119561-before-the-change.gif

I changed the header of the "Language" column in the Access database (also in this Query) then the problem was solved:

 OleDbCommand OleDbCommand_Insert = new OleDbCommand("Insert Into [BookTable](BookName,Publisher,Category,BookCode,Stock,HistoryTaken,RecipientName,ReturnDate,ReleaseDate,BookLanguage,Length,Form,Translator,Narrator,ISBN,Location,BookImage)values('" + BookName_TextBox.Text.Trim() + "','" + Publisher_TextBox.Text.Trim() + "','" + Category_ComboBox.Text.Trim() + "','" + BookCode_TextBox.Text.Trim() + "','" + Stock_ComboBox.Text.Trim() + "','" + HistoryTaken_TextBox.Text.Trim() + "','" + RecipientName_TextBox.Text.Trim() + "','" + ReturnDate_TextBox.Text.Trim() + "','" + ReleaseDate_TextBox.Text.Trim() + "','" + Language_TextBox.Text.Trim() + "','" + Length_TextBox.Text.Trim() + "','" + Form_ComboBox.Text.Trim() + "','" + Translator_TextBox.Text.Trim() + "','" + Narrator_TextBox.Text.Trim() + "','" + ISBN_TextBox.Text.Trim() + "','" + Location_TextBox.Text.Trim() + "',@Image)", OleDbConnect);

119562-after-the-change.gif
I think "Language" is the keyword in Access 2007. Is this true?
Thanks





dotnet-wpf-xaml
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

HuiLiu-MSFT avatar image
0 Votes"
HuiLiu-MSFT answered RezaJaferi1992 edited

Yes, Language is a Access database engine reserved word. You could find a complete list of MS-Access reserved keywords here. The general rule is to try to avoid using any of these words to name tables/columns. However, if you absolutely need it, you can use the [ and ] symbol around the column name to escape it.


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I guessed right, because i tested with another keyword and the same error was displayed.
Thank you.

0 Votes 0 ·