代码如下
Sql:='select max(code) as m from table';
ADOQuery1.Close;
ADOQuery1.sql.text:=sql;
ADOQuery1.open;
nMax:=ADOQuery1.fieldbyname('m').asString;Sql:='insert into table(code,name) values('+inttostr(nMax)+','+name+')';
ADOQuery1.Close;
ADOQuery1.sql.text:=sql;
ADOQuery1.open;执行后报异常:参数'dsdd'(name的值).....具体的记不清了
这段代码会有问题吗?

解决方案 »

  1.   

    Sql:='insert into table(code,name) values('+inttostr(nMax)+','+name+')';
    ---》
    改成
    Sql:='insert into table(code,name) values('+inttostr(nMax)+','''+name+''')';
    ------------------------
    nMax:=ADOQuery1.fieldbyname('m').asString;
    ---------->
    改成
    nMax:=ADOQuery1.fieldbyname('m').asInteger;
      

  2.   

    Sql:='select max(code) as m from table';
    ADOQuery1.Close;
    ADOQuery1.sql.text:=sql;
    ADOQuery1.open;
    nMax:=ADOQuery1.fieldbyname('m').asInteger;Sql:='insert into table(code,name) values('+inttostr(nMax)+','''+name+''')';
    ADOQuery1.Close;
    ADOQuery1.sql.text:=sql;
    ADOQuery1.ExecSQL;一般在使用SQL语句进行插入或者修改,删除记录的时候使用ExecSQL 而不使用Open
      

  3.   

    再說明一點,name是關鍵字,最好不要作字段名.............
      

  4.   

    同意二樓的。同時說明最好改為如下的:Sql:='select max(code) as m from table';
    ADOQuery1.Close;
    ADOQuery1.sql.text:=sql;
    ADOQuery1.open;
    nMax:=ADOQuery1.fieldbyname('m').asInteger;Sql:='insert into table(code,name) values('+inttostr(nMax)+','''+name+''')';
    ADOQuery1.Close;
    ADOQuery1.sql.clear;
    ADOQuery1.sql.text:=sql;
    ADOQuery1.ExecSQL;一般在使用SQL语句进行插入或者修改,删除记录的时候使用ExecSQL 而不使用Open