问题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' + '%''');也是一样的错误,该怎么解决?这两个小问题,还望各位高人指点,所谓难者不会,会者不难啊!
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' + '%''');也是一样的错误,该怎么解决?这两个小问题,还望各位高人指点,所谓难者不会,会者不难啊!
2:没用过 %:
看你的程序comment就是txtComment.text?
那完全可以 'select * from usertable
where ID = :id
and comment like ''%'+Trim(txtComment.text)+'%'''
1.我已经试过写两句adoquery.parameters.ParamByName('id').Value := Trim(txtID.Text);但是不行
2.我之所以要用adoquery的parameter属性,就是因为这样对于oracle数据库的performance有好处,按照你说的那样改,我干脆那个id也不用了,直接用txtID.text就行了,这就达不到我的目的了。谢谢,有什么问题,我们可以继续讨论to gxgyj:
你指什么参数名改一下?
1.可是在SQL中的确是两个一样的变量阿(都是同样的id,同样的值),,难道要我设置两个吗?这不合情理阿
2.我说了%只是SQL中的通配符阿,我那个SQL语句要组合成一个模糊查找,是一定要加的
第一个:可以这样
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;
//这样多清楚明了啊,干嘛要一定要把%放在里面去写呢
呵呵!而且确实不要用time保留字