Recently, an access project always prompts "insert into syntax error", which may cause a lot of trouble, sometimes it takes a long time for such an error to solve the problem. The "insert into syntax error" prompt contains a small amount of information, and no more detailed information can be found in the trace stack, to avoid the same errors and troubles during development. Find and explore the possibility of such errors and share them with you.
1. Keywords: If the design of your database table contains the keywords contained in access, "insert into syntax error" will appear during insertion"
For example:
String sqltext = string. Format ("insert into testtable (ID, order) values ({0 },{ 1})", 123,0 );
The preceding statement in this line fails because the "order" keyword exists in the testtable table. solution:
(1). Use [order] to process the keywords in the statement. For example:
String sqltext = string. Format ("insert into testtable (testid, [order]) values ({0 },{ 1})", 123,0 );
(2). Use [] to enclose all fields, which is used in many code generators to solve keyword conflicts. For example:
String sqltext = string. Format ("insert into testtable ([ID], [order]) values ({0 },{ 1})", 123,0 );
(3) avoid using the reserved words of access when designing the database. In this way, there will be no errors caused by keyword issues, which is also the best solution.
2. text Type: "insert into syntax error" caused by the character type. This error is usually caused by the fact that the field is in the "insert into" type during database design, and the result is that the field value is not added with ''during insert.
For example:
String sqltext = string. Format ("insert into testtable (testid, testname) values ({0 },{ 1})", 123, "cnblogs ");
Note:
Test is a numeric field, and testname is a text field
In the preceding operation, the following error occurs: "insert into syntax error"
Solution: Add ''To The Name field during the operation to solve the problem, for example:
String sqltext = string. Format ("insert into testtable (testid, testname) values ({0}, '{1}')", 123, "cnblogs ");
3. remark type: The remarks field is the same as the text field. You can solve the problem in the same way.
4. date/time type: the fields of the date/time type are the same as those of the text field. You can use the same method to solve the problem.
Keyword of the Access database:
-
Add
All
Alphanumeric
Alter
And
Any
Application
As
ASC
Assistant
Autoincrement
AVG
-B
Between
Binary
Bit
Boolean
By
Byte
-C
Char, Character
Column
Compactdatabase
Constraint
Container
Count
Counter
Create
Createdatabase
Createfield
Creategroup
Createindex
Createobject
Createproperty
Createrelation
Createtabledef
Createuser
CREATEWORKSPACE
Currency
Currentuser
-D
Database
Date
Datetime
Delete
Desc
Description
Disallow
Distinct
Distinctrow
Document
Double
Drop
-E
Echo
Else
End
Eqv
Error
Exists
Exit
-F
False
Field, Fields
Fillcache
Float, float4, float8
Foreign
Form, Forms
From
Full
Function
-G
General
GetObject
Getoption
Gotopage
Group
Group
Guid
-H
Having
-I
Idle
Ieeedouble, ieeesingle
If
Ignore
IMP
In
Index
Index, Indexes
Inner
Insert
Inserttext
Int, integer, integer1, integer2, integer4
Into
Is
-J
Join
-K
Key
-L
Lastmodified
Left
Level
Like
Logical, logical1
Long, longbinary, longtext
-M
Macro
Match
Max, Min, MOD
Memo
Module
Money
Move
-N
Name
Newpassword
No
Not
Note
Null
Number, numeric
-O
Object
Oleobject
Off
On
Openrecordset
Option
Or
Order
Orientation
Outer
Owneraccess
-P
Parameter
Parameters
Partial
Percent
Bytes
Primary
Procedure
Property
-Q
Queries
Query
Quit
-R
Real
Recalc
Recordset
References
Refresh
Refreshlink
Registerdatabase
Relation
Repaint
Repairdatabase
Report
Reports
Requery
Right
-S
Screen
Section
Select
Set
Setfocus
Setoption
Short
Single
Smallint
Some
SQL
STDev, stdevp
String
Size
Sum
-T
Table
Tabledef, tabledefs
Tableid
Text
Time, timestamp
Top
Transform
True
Type
-U
Union
Unique
Update
User
-V
Value
Values
VaR, varp
Varbinary, varchar
-W
Where
With
Workspace
-X
XOR
-Y
Year
Yes
Yesno