我的一张数据表是这样的:
表名: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;
解决方案 »
- 软件运行一天出错:external exception C000001D delphi
- BCB转delphi
- 讨论:Delphi程序员将何去何从
- 多文档窗口中关于父窗口的滚动条的问题
- 这样的多表查询是否可以在一条sql语句中实现?
- Borland Delphi v8.0 Architect Edition 好像已经出现
- 主从表中第一条记录中的从表就是显示不出来,以后的正常是怎么回事?
- 如何实行DBGRID的KEYUP/KEYPRESS功能,限得到网格内刚输入的值,高分求解.
- windows 2003 Server平台Delphi程序不支持直接调用webservice
- 如何知道参数个数和类型
- 我在按钮的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 ;//问题出在这里,编译不会报错,但运行程序会出错,它说是无效的整型值,这条语句应该怎么写才是正确的?