delphi 怎么从Access数据库取回数据并赋值给变量,不用dbEdit,dbtext之类的控件显示出来

2025-04-08 21:36:27
推荐回答(1个)
回答1:

str1:='小红';
adoquery1.close;
adoquery1.sql.text:='select * from table where name='''+str1+'''';
adoquery1.open;
if adoquery1.recordcount>0 then
begin
age:=adoquery1.fieldByName('年龄').asinteger;
phone:=adoquery1.fieldByName('手机号').asString;
job:=adoquery1.fieldByName('工作').asString;
qq:=adoquery1.fieldByName('QQ号').asString;
end;

adoquery1.close;
adoquery1.sql.text:='select * from table where ID>0 and ID<17 order by ID';
adoquery1.open;
if adoquery1.recordcount>0 then
begin
while not adoquery1.eof do
begin
age:=adoquery1.fieldByName('年龄').asinteger;
phone:=adoquery1.fieldByName('手机号').asString;
job:=adoquery1.fieldByName('工作').asString;
qq:=adoquery1.fieldByName('QQ号').asString;
adoquery1.next;
end;
end;