查询语法错误 [英] Syntax Error with Query
问题描述
我想在Delphi XE2中使用 Insert Into
查询将用户的信息插入MS Access数据库。问题是我不断得到相同的错误:
I would like to use an Insert Into
query in Delphi XE2 to insert a user's information into a MS Access Database. The problem is I keep getting the same error:
INSERT INTO语句中的语法错误
Syntax error in INSERT INTO statement
我做了一些研究,但没有明确的答案。我的源代码是:
I have done some research but there is no definitive answer. my source code is:
opendb('QuizDB.mdb');
DB.Close;
DB.SQL.Add('INSERT INTO tblUsers');
DB.SQL.Add('(FirstName,Surname,Username,Password,Grade)');
DB.SQL.Add('Values (:Firstname, :Surname, :Username, :Password, :Grade)');
Db.Parameters.ParamByName('Firstname').Value := pFirstname;
Db.Parameters.ParamByName('Surname').Value := pSurname;
Db.Parameters.ParamByName('Username').Value := pUsername;
Db.Parameters.ParamByName('Password').Value := pPassword;
Db.Parameters.ParamByName('Grade').Value := pGrade;
DB.ExecSQL;
QuizDB是数据库名称,DB是ADOQuery组件,然后p(var)是作为参数
QuizDB being the database name, DB being a ADOQuery component and then p(var) being variables received as parameters.
如何使其正常工作?
推荐答案
code> PASSWORD 是Access中的保留字如果您将其用作列名称,则必须将其括在方括号中。
PASSWORD
is a reserved word in Access so if you use it as a column name you must enclose it in square brackets.
尝试这样做:
DB.SQL.Add('INSERT INTO tblUsers ');
DB.SQL.Add('(FirstName,Surname,Username,[Password],Grade) ');
这篇关于查询语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!