问题1.
adoquery.close;
adoquery.sql.clear;
adoquery.sql.add('select * from usertable 
                   where ID = :id 
                   and time=(select max(time) 
                               from usertable 
                              where ID = :id)');
adoquery.parameters.ParamByName('id').Value := Trim(txtID.Text);
adoquery.open;
当执行adoquery.open时,弹出异常,提示“parameter objects is improperly defined. Inconsistent or incomplete information was provided”如果把“and time ...”去掉旧正确执行,这是怎么回事呢?问题2.
adoquery.close;
adoquery.sql.clear;
adoquery.sql.add('select * from usertable 
                   where ID = :id 
                     and comment like ''%:comment%''');
adoquery.parameters.ParamByName('id').Value := Trim(txtID.Text);
adoquery.parameters.ParamByName('comment').Value := Trim(txtComment.Text);
adoquery.open;
当执行adoquery.parameters.ParamByName('comment').Value 这一句时,弹出异常,提示"adoquery: parameter 'comment' not found",修改上面那句为and comment like ''%' + ':comment' + '%''');也是一样的错误,该怎么解决?这两个小问题,还望各位高人指点,所谓难者不会,会者不难啊!

解决方案 »

  1.   

    1:你有两个=:..就应该赋两次值..
    2:没用过 %:
      看你的程序comment就是txtComment.text?
    那完全可以 'select * from usertable 
                       where ID = :id 
                         and comment like ''%'+Trim(txtComment.text)+'%'''
      

  2.   

    to zzlazio:
    1.我已经试过写两句adoquery.parameters.ParamByName('id').Value := Trim(txtID.Text);但是不行
    2.我之所以要用adoquery的parameter属性,就是因为这样对于oracle数据库的performance有好处,按照你说的那样改,我干脆那个id也不用了,直接用txtID.text就行了,这就达不到我的目的了。谢谢,有什么问题,我们可以继续讨论to gxgyj:
    你指什么参数名改一下?
      

  3.   

    补充一下:这里的''%:comment%''',%只是SQL语句中的通配符,它不是delphi的内容,我想你可能理解错了,我只是把变量组合起来组成一个合法的SQL语句而已
      

  4.   

    to zzlazio
    1.可是在SQL中的确是两个一样的变量阿(都是同样的id,同样的值),,难道要我设置两个吗?这不合情理阿
    2.我说了%只是SQL中的通配符阿,我那个SQL语句要组合成一个模糊查找,是一定要加的
      

  5.   

    time改成_time或其他不与保留字冲突的名字.
      

  6.   

    sql.add('select * from usertable  where ID = :id  and comment like ''%:comment%''');改成下面这样就可以了sql.Add('select * from usertable  where ID = :xID and comment like ''%'+Edit1.Text+'%''');
      

  7.   

    这个问题我之前我碰到过
    第一个:可以这样
    adoquery.sql.add('select * from usertable 
                       where ID = :id 
                       and time=(select max(time) 
                                   from usertable 
                                  where ID = :id)');
    adoquery.parameters[0].Value := Trim(txtID.Text);
    adoquery.parameters[1].Value := Trim(txtID.Text);
    adoquery.open;
    或者
    adoquery.sql.add('select * from usertable 
                       where ID = :id 
                       and time=(select max(time) 
                                   from usertable 
                                  where ID = :id1)');
    adoquery.parameters.ParamByName('id').Value := Trim(txtID.Text);
    adoquery.parameters.ParamByName('id1').Value := Trim(txtID.Text);
    adoquery.open;
    第二个问题:
    adoquery.sql.add('select * from usertable 
                       where ID = :id 
                         and comment like :comment);
    adoquery.parameters.ParamByName('id').Value := Trim(txtID.Text);
    adoquery.parameters.ParamByName('comment').Value := '%'+Trim(txtComment.Text)+'%';
    adoquery.open;
    //这样多清楚明了啊,干嘛要一定要把%放在里面去写呢
      

  8.   

    不是太清楚,但是好像一般把SQL语句写成多行的,就会出毛病,
    呵呵!而且确实不要用time保留字