查询问题。高手指教。
帮帮我吧!下面的代码,想实现三个控件选择任意其中的内容
组合都能查询。编译执行提示。
选择第一个控件中的内容提示。
list index out of bounds(1)
选择第二个控件中的内容提示
list index out of bounds(2)
选择第三个控件中的内容提示
list index out of bounds(3)
我不知道如何是好,我想找一个高人帮我试一试,指出一条光明大道。
我虚心好学。痛恨那些只说些无关痛痒的话的人、
procedure TForm6.BitBtn1Click(Sender: TObject);
var
i:integer;
var
check:array [1..4] of string;
var
sun:array [1..4] of string;
var
s2,s1,a1:string;
var
p:integer;
begin
query1.DatabaseName:='sun';
for i:=1 to 3 do
begin
if i=1 then
begin
Check[i]:='fanwei';
end;
if i=2 then
begin
Check[i]:='gongre';
end;
if i=3 then
begin
Check[i]:='dizhi';
end
end;
for i:=1 to 3 do
begin
if i=1 then
begin
sun[i]:=sun1.Text;
end;
if i=2 then
begin
sun[i]:=sun2.Text;
end;
if i=3 then
begin
sun[i]:=sun3.Text;
end
end;
query1.SQL.Clear;
query1.SQL.Add('select * from "housesource" as s where ');
for i:=1 to 3 do
if sun[i]<>'' then
begin
s2:=inttostr(i);
s1:='s.'+'"'+check[i]+'"'+'=:p'+s2+' and ';
a1:=a1+s1;
end;
a1:=a1+'s."id">:p20';
query1.SQL.Add(a1);
edit2.Text:=query1.SQL.Text;
query1.Prepare;
p:=0;
for i:=0 to 2 do
if sun[i+1]<>'' then
bfegin
query1.Params[p].AsString:=sun[i+1];
p:=p+1;
end;
query1.Params[p+1].AsInteger:=1;
query1.Open;
datasource1.DataSet:=query1;
dbgrid1.DataSource:=datasource1;
end;