“insert into statement”中的语法错误

时间:2016-09-22 13:28:48

标签: sql delphi ms-access

我正在为学校制作一个PAT,请你帮我解决我的代码一直遇到同样的错误。

这是我的第一个

DMrecord.qryMembers.Paramcheck := true;
DMrecord.qryMembers.SQL.Text := 'INSERT INTO Members '
            +'([MemberName],[MemberSurname],[Age],[CellNumber],[EmailAddress])'
            +' VALUES '
            +'(:MemberName, :MemberSurname, :Age, :CellNumber,:EmailAddress)';
             DMrecord.qryMembers.Parameters.ParamByName('MemberName').Value := sname;
             DMrecord.qryMembers.Parameters.ParamByName('MemberSurname').Value := ssurname;
             DMrecord.qryMembers.Parameters.ParamByName('Age').Value := iage;
             DMrecord.qryMembers.Parameters.ParamByName('CellNumber').Value := icellphone;
             DMrecord.qryMembers.Parameters.ParamByName('EmailAddress').Value := semail;
             DMrecord.qryMembers.ExecSQL;

这是我的第二个

DMrecord.qryResults.Paramcheck := true;
DMrecord.qryResults.SQL.Text := 'INSERT INTO Member Result '
            +'([ClubNumber],[Event],[AverageTime/Distance],[Numberofcompetition],[Agegroup])'
            +' VALUES '
            +'(:ClubNumber, :Event, :AverageTimeDistance, :Numberofcompetition, :Agegroup)';
            DMrecord.qryResults.Parameters.ParamByName('ClubNumber').Value := iclubnumber;
            DMrecord.qryResults.Parameters.ParamByName('Event').Value := sevent;
            DMrecord.qryResults.Parameters.ParamByName('AverageTimeDistance').Value := ravg;
            DMrecord.qryResults.Parameters.ParamByName('Numberofcompetition').Value := inumcomps;
            DMrecord.qryResults.Parameters.ParamByName('Agegroup').Value := sagegroup;
            DMrecord.qryResults.ExecSQL;

我希望这会让事情变得更容易 并感谢您的帮助

1 个答案:

答案 0 :(得分:4)

在第二个查询中,您使用

'INSERT INTO Member Result '

这会导致错误,因为表名包含空格而且没有被转义。你需要用括号括起来:

'INSERT INTO [Member Result] '