var
s,s1,s2,s3,s4:string;
value1,value2:string;
begin
s:='select * from house where 交易类型=买卖';
s1:='';
s2:='';
s3:='';
s4:='';
if combobox10.text<>'房屋用途' then
begin
s1:=combobox10.text;
s:=s+'and 房屋用途='''+s1+'''';
end;
if combobox11.text<>'层次' then
begin
s2:=combobox11.text;
s:=s+'and 房屋用途='''+s2+'''';
end;
if combobox12.text<>'房型' then
begin
s3:=combobox12.text;
value1:=copy(s3,0,1);
value2:=copy(s3,4,1);s:=s+'and 房型室='''+value1+'''and 房型厅='''+value2+''' ';
end;
if combobox13.text<>'房屋类型' then
begin
s4:=combobox13.text;
s:=s+'and 房屋类型='''+s4+'''';
end;
with datamodule3.ADOQuery1 do
begin
close;
sql.clear;
sql.add(s);
open;
end;
end;提示错误: 参数不足,期待是1;难道一定要用参数吗?
不用参数的话该怎么改?
各位帮帮忙啦
s,s1,s2,s3,s4:string;
value1,value2:string;
begin
s:='select * from house where 交易类型=买卖';
s1:='';
s2:='';
s3:='';
s4:='';
if combobox10.text<>'房屋用途' then
begin
s1:=combobox10.text;
s:=s+'and 房屋用途='''+s1+'''';
end;
if combobox11.text<>'层次' then
begin
s2:=combobox11.text;
s:=s+'and 房屋用途='''+s2+'''';
end;
if combobox12.text<>'房型' then
begin
s3:=combobox12.text;
value1:=copy(s3,0,1);
value2:=copy(s3,4,1);s:=s+'and 房型室='''+value1+'''and 房型厅='''+value2+''' ';
end;
if combobox13.text<>'房屋类型' then
begin
s4:=combobox13.text;
s:=s+'and 房屋类型='''+s4+'''';
end;
with datamodule3.ADOQuery1 do
begin
close;
sql.clear;
sql.add(s);
open;
end;
end;提示错误: 参数不足,期待是1;难道一定要用参数吗?
不用参数的话该怎么改?
各位帮帮忙啦
s1:='';
s2:='';
s3:='';
s4:='';
if combobox10.text<>'房屋用途' then
begin
s1:=combobox10.text;
s:=s+'and 房屋用途='''+s1+''''
\\我觉得是你的语句有问题
比如有些地方应该有个空格隔开的,你忽略了
如:
'select * from house where 交易类型=买卖'+'and 房屋用途='''+s1+''''
就变为:
select * from house where 交易类型=买卖and 房屋用途//
很明显,“买卖”和“and”之间应该有个空格
所以
s:=s+'and 房屋用途='''+s1+''''应该是
s:=s+' and 房屋用途='''+s1+''''
这样是正解:
var
s,s1,s2,s3,s4:string;
value1,value2:integer;
begin
s:='select * from house where 交易类型=:y and 数据性质=:z';
s1:='';
s2:='';
s3:='';
s4:='';
if combobox10.text<>'房屋用途' then
begins:=s+'and 房屋用途=:a';
s1:=combobox10.text;
end;
if combobox11.text<>'层次' then
begins:=s+'and 房屋用途=:b';
s2:=combobox11.text;
end;
if combobox12.text<>'房型' then
begin
s:=s+'and 房型室=:c1 and 房型厅=:c2 ';
s3:=combobox12.text;
value1:=strtoint(copy(s3,0,1));
value2:=strtoint(copy(s3,4,1));
end;
if combobox13.text<>'房屋类型' then
begins:=s+'and 房屋类型=:d';
s4:=combobox13.text;
end;
with datamodule3.ADOQuery1 do
begin
close;
sql.clear;
sql.add(s);
paramByName('y').asstring:='买卖';
paramByName('z').asstring:='详细数据';
if s1<>'' then paramByName('a').asstring:=s1;
if s2<>'' then paramByName('b').asstring:=s2;
if s3<>'' then
paramByname('c1').asinteger:=value1;
paramByname('c2').asinteger:=value2;
if s4<>'' then paramByName('d').asstring:=s4;
open;
end;
end;
我有点不理解的是
为什么将if s1<>'' then
if s2<>'' then
if s3<>'' then
注销掉就无会出现
paramter'a' not found
而paramByName('y').asstring:='买卖';这句前却不用
if s1<>'' then 这名与上面之间的关系怎样?
这句不对s:='select * from house where 交易类型=''买卖''';s:=s+'and 房屋用途='''+s1+'''';->s:=s+'and 房屋用途=' +''''+s1+'''';s:=s+'and 房屋用途='''+s2+'''';->s:=s+'and 房屋用途='+''''+s2+'''';