我的一张数据表是这样的:
表名: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[0..3] 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;sql.Clear;
sql.Add('select no2 from info where no=''1''');
open;
for i:=1 to count do
begin
arr[i]:=fieldbyname('no2').AsInteger ;//这里在运行时会出错
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[0..3] 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;sql.Clear;
sql.Add('select no2 from info where no=''1''');
open;
for i:=1 to count do
begin
arr[i]:=fieldbyname('no2').AsInteger ;//这里在运行时会出错
end;
解决方案 »
- 求教GroupBox1的控制属性问题
- 关于控件数组的不明白,应该还有很多初学的朋友都不明白的问题 请高手们帮忙解答下!!
- 怪,在win.ini文件里找不到信息
- file not found'frx6.dcp'
- 初学者的简单小问题请高手多指教[:)]
- 大侠们:DBGRID的问题
- delphi第二张盘上的ABC控件怎么不能用啊?
- 我想自己继承TEdit类,自己绘制EDIT的外形
- Delphi将一个Integer值写入磁盘文件,怎么用VC++将其正确读出?
- 关于email发送邮件的错误
- 我在按钮的CLICK事件中定义PChar变量p然后p := StrAlloc(2),结果用StrPas(p)居然返回按钮的Caption ?
- delphi如何编程实现将应用程序创建快捷方式到windows启动菜单
begin
arr[i]:=fieldbyname('no2').AsInteger ;//下标是0,所以出错了
end;
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 ;//这里在运行时会出错
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[1..4] 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; sql.Clear;
sql.Add('select no2 from info where no=''1''');
open;
for i:=1 to count do
begin
arr[i]:=fieldbyname('no2').AsInteger ;//这里在运行时会出错
end;
不好意思,写错了
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 ;//这里在运行时会出错
end;
刚才写错了arr[i]:=fieldbyname('no2').AsInteger ;//问题出在这里,编译不会报错,但运行程序会出错,它说是无效的整型值,这条语句应该怎么写才是正确的?