数据库问题?在线给分,不够再加!!
想要通过combobox选择一项,进行查询,查询到的表的各项内容添加到dbedit中去,但是
为什么查询只能显示一次结果呢?第二次在combobox中选择,就会出现出错信息:dbedit5找不到!!
窗体上有table1,datasource1,query1,分别设置了table1.name=
table1.active=true
datasource.datase=table1,
急死了,请各位大虾指条明路!!
procedure TForm30.suiComboBox1Change(Sender: TObject);
var
i:integer;
s:string;
begin
suidbmemo1.datafield:='';
with query1 do
begin
s:='select sname from area_information.db'+' where sname="'+ suiComboBox1.text+'"';
sql.Text:=s;
open;
for i:=1 to recordcount do
begin
suiComboBox1.Items.Add(fieldbyname('sname').AsString);
next;
end;
close;
end;
end;
procedure TForm30.suiButton1Click(Sender: TObject);
var
asql:string;
begin
if suiComboBox1.text<>'' then asql:='and (sname="'+suiComboBox1.Text+'") ';
if asql<>'' then
begin
with form30 do
begin
query1.close;
query1.SQL.Text:='select * from area_information.db where sname<>"" '+asql;
datasource1.DataSet:=query1;
query1.open;
end;
if suiComboBox1.text<>'' then
begin
suidbedit1.DataField:='sarea_position';
suidbedit2.DataField:='sarea_temperature';
suidbedit3.DataField:='sarea_climate';
suidbedit4.DataField:='ssoil_humidity';
suidbedit5.DataField:='Ssoil_acid';
suidbmemo1.datafield:='conclusion';
end;
end;
end;
procedure TForm30.suiButton2Click(Sender: TObject);
begin
suidbedit1.Text:='';
suidbedit2.Text:='';
suidbedit3.Text:='';
suidbedit4.Text:='';
suidbedit5.Text:='';
suidbmemo1.Clear;
end;
procedure TForm30.FormCreate(Sender: TObject);
var i:integer;
begin
suiComboBox1.Text:='';
with query1 do
begin
Close;
SQL.Clear;
sql.text:='select Sname from area_information.db';
prepare;
open;
suiComboBox1.Clear;
suiComboBox1.Items.Add('');
for i:= 1 to recordcount do
begin
suiComboBox1.Items.Add(fieldbyname('Sname').asstring);
next;
end;
close;
end;
end;