请问如何将数据库某个字段的值循环写入一个数组(50分)

  • 主题发起人 主题发起人 lebronjames
  • 开始时间 开始时间
L

lebronjames

Unregistered / Unconfirmed
GUEST, unregistred user!
各位大侠,我想把ACCESS数据库里的某一字段的所有记录的值取出来循环放入一个动态一维数组,这是我的代码:
i:integer;
a:array of string;
begin
for i:=0 to adotable1.FieldCount-1 do
begin
a:=adotable1.Fields.Fields['姓名'].Value;
end;
end;
编译没问题,但是运行的时候就提示:存取地址违例发生在模块....
请问各位代码哪儿有点问题啊?
 
i:integer;
a:array of string;
begin
setlength(a,adotable1.recordcount);
adotable1.first;
for i:=0 to adotable1.recordCount-1 do
begin
a:=adotable1.Fieldbyname('姓名').asstring;
adotable1.next;
end;
end;
 
这样写的话,数据库没有循环更新啊!
with adotable1 do
begin
i:=0;
first;
while not eof do
begin
a:=adotable1.fields.fields['姓名'].value;
i;=i+1;
next;
end;
end;
 
TYZhang 您好:
谢谢谢谢!!按照您的代码,问题已经解决了!!
nbu04dx001 您好:
不明白您说的数据库更新是指什么,我只想把数据库里的字段的值读出来放入数组进行操作
 
谢谢,分数送给您了
 
后退
顶部