tempid := adorecievequery.fieldbyname('SM_ID').AsInteger;...
为什么执行如下语句出错??
adorecievequery.SQL.Text:='update dbo.tbl_SMReceived set readed=1 where SM_ID = tempid '
adorecievequery.ExecSQL; SM_ID字段是整形 int where SM_ID = tempid  应该如何写才对?

解决方案 »

  1.   

    where SM_ID = '+inttostr(tempid); 
      

  2.   

    或者这样写(我比较喜欢这样写,不用转来转去的):
    tempid := adorecievequery.fieldbyname('SM_ID').AsInteger; 
    with adorecievequery do
    begin
      close;
      SQL.Text:='update dbo.tbl_SMReceived set readed=1 where SM_ID = :tempid ';
      Parameters.parambyname('tempid').value := tempid;
      ExecSQL; 
      

  3.   

    如果变量tempid的类型是stirngadorecievequery.SQL.Text:='update dbo.tbl_SMReceived set readed=1 where SM_ID = ' + tempid 如果变量tempid的类型是integeradorecievequery.SQL.Text:='update dbo.tbl_SMReceived set readed=1 where SM_ID = ' + IntToStr(tempid)
      

  4.   

    tempid 肯定 是int型,只是我上面定义了没有写。
      

  5.   

    adorecievequery.SQL.Text:='update dbo.tbl_SMReceived set readed=1 where SM_ID = '+InttoStr(tempid); 
      

  6.   

    如果是insert,select也都可以利用参数传弟的方式的,如下:with adoquery1 do
    begin
      close;
      sql.text := ' insert into t1(c1,c2) values(:c1,:c2)';
      parameters.parambyname('c1').value := '';
      ....
      execsql;
    end;查询和你的update差不多.
    这里的:c1,:c2名称可以随便命名的
      

  7.   

    采用绑定参数是有好处的,可以减少数据库上的解析次数,提高速度,这点在Oracle数据库中很重要,是影响性能的一个重要因素