我的一张数据表是这样的:
表名:info
字段名:no,no2
no no2
1 0
1 1
1 2
1 3
2 1
... ... 通过sql,把no所对应的数据取出并存入到一维数组中
例如:no=1 时,对应的no2值为:0,1,2,3;怎样把0,1,2,3依次取出并存入到一维数组中
我的代码是这样的:
var
i,j,count:integer;
arr:array of integer;
begin
with ADOQuery1 do
begin
sql.Clear;
sql.Add('select count(*) as count from info where no=''1''');
open;
count:=fieldbyname('count').AsInteger; setlength(arr,count);
sql.Clear;
sql.Add('select no2 from info where no=''1''');
open;
for i:=0 to count-1 do
begin
arr[i]:=fieldbyname('no2').AsInteger ;//这里应该怎么写才能实现把no2的数据依次
写入到一维数组中,是不是需要 cell之类的,请大虾们指教end;
表名:info
字段名:no,no2
no no2
1 0
1 1
1 2
1 3
2 1
... ... 通过sql,把no所对应的数据取出并存入到一维数组中
例如:no=1 时,对应的no2值为:0,1,2,3;怎样把0,1,2,3依次取出并存入到一维数组中
我的代码是这样的:
var
i,j,count:integer;
arr:array of integer;
begin
with ADOQuery1 do
begin
sql.Clear;
sql.Add('select count(*) as count from info where no=''1''');
open;
count:=fieldbyname('count').AsInteger; setlength(arr,count);
sql.Clear;
sql.Add('select no2 from info where no=''1''');
open;
for i:=0 to count-1 do
begin
arr[i]:=fieldbyname('no2').AsInteger ;//这里应该怎么写才能实现把no2的数据依次
写入到一维数组中,是不是需要 cell之类的,请大虾们指教end;
解决方案 »
- 跨进程给dbgride赋值的问题,大侠帮忙,谢谢!
- 请教简单的多线程问题
- 请高手指教,有关结构问题
- 请教如何写一个基于文件的小型数据库?
- ClientDataSet的providername属性怎样在代码中赋值?
- 初级问题求救:Delphi7中找不到'ExcelXP.dcu'
- 赋初值问题
- 请问在一个Button上的添加颜色属性的写方法怎么写?
- to cobi(我是小新),txinfo(冰炎两重天) 两位高的在吗?
- 数据插入问题A
- 这个什么错误啊!!(546): Identifier redeclared: 'Tfrm_gate.SpeedButton2Click'
- 这个函数执行有误,但是try except end不起作用,一直报错,请高手帮忙处理下吧,谢谢了!
arr:array of Integer;
i:Integer;
begin
With ADOQuery1 do
begin
Close;
sql.Clear;
sql.Add('select * as count from info where no=''1''');
open;
SetLength(arr,RecordCount);
i:=0;
DisableControls;
while not Eof do
begin
arr[i]:=FieldByName('No2').AsInteger;
Inc(i);
Next;
end;
EnableControls;
end;
EnableControls;
这两条语句是什么意思?我不明白
请大虾简单请解一下
Thank you !
不过最好用try..finaly..end; 防止发生意外
try
adoQuery1.disablecontrols;
adoQuery1.close;
......
adoQuery1.open;
finally
adoQuery1.enablecontrols;
end;
如果DisableControls,那么在当前记录位置移动时DataSet就不会去刷新感知控件,这样就提高了遍历DataSet的效率。EnableControls就是恢复数据集的“感
知能力”
arr:array of Integer;
i:Integer;
begin
With ADOQuery1 do
try
DisableControls; Close;
sql.Text:='select count(*) from info where no=''1''';
open; SetLength(arr,Fields[0].AsInteger);
Close;
SQL.Text := 'select no2 from info where no=''1''';///++++
Open;
i:=0;
while not Eof do
begin
arr[i]:=FieldByName('No2').AsInteger;
Inc(i);
Next;
end;
finally
EnableControls;
end;