2

调用此查询时,我在运行时不断收到语法错误。

adoquery1.Active := false;
adoquery1.SQL.Clear;
SQLQuery := 'INSERT INTO Comics ';
SQLQuery := SQLQuery + '(Name,Issue,Series,Volume,Poster,';
SQLQuery := SQLQuery + 'Desc,Writer,Artist,Read,Link,Extra) ';
SQLQuery := SQLQuery + 'VALUE('+ quotedstr(SeriesName+' '+IssueNumber);
SQLQuery := SQLQuery + ','+ quotedstr(IssueNumber);
SQLQuery := SQLQuery + ','+ quotedstr(SeriesName);
SQLQuery := SQLQuery + ','+ quotedstr(VolumeNumber);
SQLQuery := SQLQuery + ','+ quotedstr(Poster);
SQLQuery := SQLQuery + ','+ quotedstr(Desc);
SQLQuery := SQLQuery + ','+ quotedstr(Writer);
SQLQuery := SQLQuery + ','+ quotedstr(Artist);
SQLQuery := SQLQuery + ','+ quotedstr(haveRead);
SQLQuery := SQLQuery + ','+ quotedstr(filelink);
SQLQuery := SQLQuery + ','+ quotedstr(Extra);
SQLQuery := SQLQuery + ')';
memo1.Text := SQLQuery;
adoquery1.SQL.Add(SQLQuery);
adoquery1.Active := true;

当我执行 memo1.text = sqlquery 时,它看起来没问题,有什么建议吗?这就是我在 memo1.text 中得到的 ..

INSERT INTO Comics (Name,Issue,Series,Volume,Poster,Desc,Writer,Artist,Read,Link,Extra VALUE('xmen 8','8','xmen','1','na','Some Description','BOBwriter','BOBArtist','Yes','C:\Comics\xmen8.cbr','Some Extra info')
4

3 回答 3

5

Desc是一个保留字,所以你应该使用[Desc]或用反引号括起来(我不知道你使用的是哪个数据库)。
更多:我认为应该是VALUES(而不是VALUE(

INSERT INTO Comics 
    (Name, Issue, Series, Volume, Poster, [Desc],
     Writer, Artist, [Read], Link, Extra) 
VALUES
    ('xmen 8', '8', 'xmen', '1', 'na', 'Some Description',
     'BOBwriter', 'BOBArtist', 'Yes', 'C:\Comics\xmen8.cbr','Some Extra info')
于 2012-05-24T06:37:41.247 回答
3

Enclose the Reserved Word DESC with brackets

adoquery1.Active := false;
adoquery1.SQL.Clear;
SQLQuery := 'INSERT INTO Comics ';
SQLQuery := SQLQuery + '(Name,Issue,Series,Volume,Poster,';
SQLQuery := SQLQuery + '[Desc],Writer,Artist,[Read],Link,Extra) ';
SQLQuery := SQLQuery + 'VALUES ('+ quotedstr(SeriesName+' '+IssueNumber);
SQLQuery := SQLQuery + ','+ quotedstr(IssueNumber);
SQLQuery := SQLQuery + ','+ quotedstr(SeriesName);
SQLQuery := SQLQuery + ','+ quotedstr(VolumeNumber);
SQLQuery := SQLQuery + ','+ quotedstr(Poster);
SQLQuery := SQLQuery + ','+ quotedstr(Desc);
SQLQuery := SQLQuery + ','+ quotedstr(Writer);
SQLQuery := SQLQuery + ','+ quotedstr(Artist);
SQLQuery := SQLQuery + ','+ quotedstr(haveRead);
SQLQuery := SQLQuery + ','+ quotedstr(filelink);
SQLQuery := SQLQuery + ','+ quotedstr(Extra);
SQLQuery := SQLQuery + ')';
memo1.Text := SQLQuery;
adoquery1.SQL.Add(SQLQuery);
adoquery1.Active := true;
于 2012-05-24T06:41:29.093 回答
2

use Values instead of value.
Desc and Read are reserved keywords, so enclose then in square brackets.
You forgot to keep closing parenthesis before Values keyword.

INSERT INTO Comics 
            (Name, 
             Issue, 
             Series, 
             Volume, 
             Poster, 
             [Desc], 
             Writer, 
             Artist, 
             [Read], 
             Link, 
             Extra) 
VALUES     ('xmen 8', 
            '8', 
            'xmen', 
            '1', 
            'na', 
            'Some Description', 
            'BOBwriter', 
            'BOBArtist', 
            'Yes', 
            'C:\Comics\xmen8.cbr', 
            'Some Extra info') 
于 2012-05-24T06:42:20.713 回答