Insert Into Syntax error

  • Thread starter Thread starter Jon S via DotNetMonster.com
  • Start date Start date
J

Jon S via DotNetMonster.com

Hi all,

Please can someone tell me what's wrong with the following INSERT INTO
statement. The error message return that an 'INSERT INTO syntax error' I
have a feeling that it is because of the 'Sensor offset' field name having a
space between the two names, although it is like that in the MS Access 2000
database that I'm using? But I would like someone to clarify or suggest the
problem.

da_Target.InsertCommand.CommandText = "INSERT INTO Layouts (Name,Picture,
Sensor offset) VALUES ('David',' ',7)";

Thank you.
 
Hey Miha

Thanks for replying. The previous code line was to establish the problem.
The actual code line Im using is below. The memory variable str_TargetFields
contains the list of fields/columns that will be inputted with data from the
list of values in str_TargetValues. Do I include the [ ] around the
str_TargetFields variable or should I include the [ ] individually around
each field/column name?

Thank you.

da_Target.InsertCommand.CommandText = "INSERT INTO Layouts (" +
str_TargetFields + ") VALUES (" + str_TargetValues + ")";
 
"INSERT INTO Layouts ([Name],[Shape],[Total width],[Total depth],[Useable
width],[Useable depth],[Number across],[Number down],[Offset right],[Offset
down],[Density],[Sensor type],[Sensor offset],[Gap size],[Cutter],[paper],
[Sensor Number],[Picture]) VALUES ('Colour Bed - 8x6 (Epson)','Rectangular',
'10800','7920','10800','7920','1','1','0','0','0','','0','0','False','False',
'0','')"

Is this how I'm supposed to do it?
 
To be on the safe side - yes.
You might also embed table name into square brackets.
 
On Thu, 20 Oct 2005 16:21:17 +0200, "Miha Markic [MVP C#]" <miha at rthand com> wrote:

¤ To be on the safe side - yes.
¤ You might also embed table name into square brackets.

Or change the name of the name column altogether. It is an Access reserved word.


Paul
~~~~
Microsoft MVP (Visual Basic)
 
Paul is correct - the best way is to avoid reserved names and blanks for
naming entities.
However, if you can't set that names for whatever the reason is then you
have to use the square brackets.
 
Back
Top