最近在写一个网站时,发生一个比较郁闷的错误
异常详细信息: System.Data.OleDb.OleDbException: INSERT INTO 语句的语法错误。
可是我把插入语句改成这们后
OleDbHelper.ExecuteNonQuery(OleDbHelper.ConnectionStringLocalTransaction, CommandType.Text, "insert into [UserList] (UserName,PassWord) VALUES ('kkk', 'lll')", null);、
还是弹出同样的错误。
最后才发现,PassWord是Access数据库的关键字,改了之后就通过了。
下面罗列了一些关键字
-A
ADD
ALL
Alphanumeric
ALTER
AND
ANY
Application
AS
ASC
Assistant
AT
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 BY
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
Password
PERCENT
PIVOT
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
Size
SMALLINT
SOME
SQL
StDev, StDevP
STRING
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
最后说明一下:在Access中和在MS SQL中一样,对关键字的转义是使用“[”和“]”的,比如你的数据库中某个表中有以上述关键字作为字段名的,记得在该字段前后分别加上“[”和“]”,如,,,不过建议还是尽量避免使用关键字。
另外友情提示:如果遇见报“insert into"语句错误的情况,多半就是因为你使用关键字了。记得转义或者更改字段名。