将Ttable的数据存到一个数组中

thunderingman 2007-11-19 03:56:15
表的内容
1 2 3 4
5 6 7 8
9 10
想将它寸到一个数组里面
array[1 2 3 4 5 6 7 8 9 10]
怎么办?
采用TDatabase TTable TDatasource TGrid控件在做的
...全文
79 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
fang_liang 2008-06-14
  • 打赏
  • 举报
回复
我也正好遇到这个问题,
wangxuelid 2007-11-20
  • 打赏
  • 举报
回复
1:While not AdoQuery1.Eof do //这个循环一次对你的表所有的列取值,并付值到数组
2:column分别代表 id a b c d
yangtxiang2007 2007-11-20
  • 打赏
  • 举报
回复
先定义一个动太的二维数组,然后赋值过去就行了

function ADOTableToArray;
var
CellValue:Array of Array of variant;
I,J:integer
begin
if not ADOTable.active then exit;
setLength(CellValue,ADOTable.Fields.count); //设置数组列数
while I<ADOTable.RecordCount do
begin
Inc(I);
For J:=low(CellValue) to High(CellValue) do
begin
setlength(CellValue[J],I); 设置数组行数
CellValue[J,I]:=ADOTable.Fields[J].Value;
end;
ADOTable.Next;
end;
end;
之后就可以用CellValue[I,J]开读取其值了
thunderingman 2007-11-19
  • 打赏
  • 举报
回复
各位帮忙啊,小弟这个弄不出来了
thunderingman 2007-11-19
  • 打赏
  • 举报
回复
没人知道吗???
thunderingman 2007-11-19
  • 打赏
  • 举报
回复
加一个adoquery控件?你这里面column是指字段名???
我的表的格式是
id a b c d
1 1 2 3 4
2 5 6 7 8
3 9 10 11 12

column怎么写呢

没有直接指向的吗 象c语言一样 7就是table[2][3]或者table[7]之类的
我想对表中每个知道位置的数值定位取出来,有方法吗??
wangxuelid 2007-11-19
  • 打赏
  • 举报
回复
procedure TForm1.Button10Click(Sender: TObject);
var
i: integer;
Arry_ : array [1..10] of string;
begin

i:=1
While not AdoQuery1.Eof do
Begin
if AdoQuery1.FieldByName('column')<>'' then//想过滤条件在这里写
Begin
arry_[i]:= AdoQuery1.FieldByName('column').AsString ;
i:=i+1;
End
Else
Begin
i:=i+1;
End;
***
AdoQuery1.next;
End;
end;
//死了,发烧不行了,SORRY,就写到这里,,

2,497

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧