Question INSERT INTO exception

gwbasic

New member
Joined
Apr 25, 2010
Messages
4
Programming Experience
10+
Hi, everybody,
i've dev a program that access to an mdb database and insert a new record with the command INSERT INTO but when i execute the db command with ExecuteNonQuery the program catch an exception that i did not understand.
I post the oledbcommand line and the fields of the access mdb.

objData = New CData(Application.StartupPath & "\Access.mdb")
objData.DatabaseCommand("INSERT INTO Invoice " & _
"(Number, Notes, Description, Quantity, " & _
"Cost, Import, ServicePayment, Tariff, SimgleUse, " & _
"BedAdd, Kids) VALUES (" & NF & ", '" & StringIntNotes & "', '" & _
StringIntDescription & "', '', '" & StringCost & "', '', '" & _
StringServicePayment & "', '" & StringTariff & "', '" & _
StringSimgleUse & "', '" & StringBedAdd & "', '" & StringKids & "')")

Where:
NF is INTEGER
StringIntNotes, StringIntDescription, StringCost, StringServicePayment, StringTariff, StringSimgleUse, StringBedAdd, StringKids are STRING

And the Access fields:
IDNumbInvoice: Primary Key - AutoIncrement Numeric Field
Number: Numeric
Notes: Text
Description: Text
Quantity: Text
Cost: Text
Import: Text
ServicePayment: Text
Tariff: Text
SimgleUse: Text
BedAdd: Text
Kids: Text

When i try to insert the new record the exception is "Syntax error in the expression INSERT INTO".
Thanks to all that try to solve my problem.
 
Last edited:

r3plica

Well-known member
Joined
Mar 4, 2010
Messages
86
Programming Experience
3-5
just try putting square bracked around the 'Description' field.

[Description]
 

gwbasic

New member
Joined
Apr 25, 2010
Messages
4
Programming Experience
10+
Solved

tnx to all.

i've solved my problem.
the exception was generated because there was a field named with one reserved word.

changed the name of the field i've solved all.

tnx
 
Top Bottom