帮我寻找程序中错误(50分)

  • 主题发起人 主题发起人 hqlww
  • 开始时间 开始时间
H

hqlww

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.Button2Click(Sender: TObject);
var
s:string;
begin
s:='';
if radiobutton1.checked then s:=s+'dept like:dept'
else if radiobutton2.checked then s:=s+'salary>:salary'
else if radiobutton3.checked then s:=s+'sex like:sex';
if s<>'' then
begin
close;
query1.sql.clear;
query1.sql.add('select * from yuangong.db');
query1.sql.add('where'+s);
if radiobutton1.checked then
query1.params.paramValues['dept']:=combobox1.text
else if radiobutton2.checked then
query1.params.paramValues['salary']:=strtoint(edit2.text)
else query1.params.paramValues['sex']:=combobox2.text;
query1.open;
end;
end;

这个程序是为了实现查询功能的,运行时出现错误,请指教!
project project2.exe raised exception class EDBEngineError with message'Invalid use of keyword.
token:like?
line Number:2'.Process stopped Use Step or Run to continue这个是什么意思啊?
 
like :dept+'%'
 
select * from yuangong.db where dept like:dept
错误信息是说你的LIKE写得有问题,我看好像是有问题
 

你不用参数形式,直接将你的内容凑成SQL语句,然后单步跟踪,
就可调试你的错误所在了。
 
if radiobutton1.checked then s:=s+'dept like:dept'
else if radiobutton2.checked then s:=s+'salary>:salary'
else if radiobutton3.checked then s:=s+'sex like:sex';
你的参数不要和字段定义的同名,
if radiobutton1.checked then s:=s+'dept like:dept_1'
else if radiobutton2.checked then s:=s+'salary>:salary_1'
else if radiobutton3.checked then s:=s+'sex like:sex_1';
试试行不行,
 
轩辕散光、free_knight谢谢你们对我的解答,但是我做了,修改了,还是不对的,你们以前遇到过这样的问题吗?能告诉我再怎么试验吗?谢谢!
 
使用like语句要%,不用就只能用where语句
 
procedure TForm1.Button2Click(Sender: TObject);
var
s:string;
salary_1,salary_2:string;
begin
s:='';
if radiobutton1.checked then s:=s+'dept like :dept_1'
else if radiobutton2.checked then begin
salary_1:=edit2.text;
salary_2:=edit3.text;
s:=s+'salary between :salary_1 and :salary_2'
end
else if radiobutton3.checked then s:=s+'sex like :sex_1';
if s<>'' then
begin
query1.close;
query1.sql.clear;
query1.sql.add('select * from yuangong.db');
query1.sql.add('where '+s);
if radiobutton1.checked then
query1.params.paramValues['dept_1']:=combobox1.text
else if radiobutton2.checked then
begin
query1.params.paramValues['salary_1']:=strtoint(edit2.text);
query1.params.paramValues['salary_2']:=strtoint(edit3.text);
end
else query1.params.paramValues['sex_1']:=combobox2.text;
query1.execsql;
query1.open;
end;
end;
 
'''' 的问题

else if radiobutton3.checked then s:=s+'sex like '+''''combobox2.text+''''
其他类似
 
query1.params.paramValues['dept']:=combobox1.text
改为:
query1.params.paramValues['dept']:=combobox1.text+‘%’;
query1.params.paramValues['sex']:=combobox2.text;
改为:
query1.params.paramValues['sex']:=combobox2.text+‘%’;


 
多人接受答案了。
 
后退
顶部