程序如下:
在执行到query1.Fields.Fields[0].Value程序报错"List Index out of bounds(0)"
请问如何解决?????
用TQuery和TTable控件如何在表中取值?????
procedure TForm2.Button1Click(Sender: TObject);
var
no,gnum:integer;
gprice:real;
gno,gowner,sno,gname:string;
begin
if pagecontrol1.ActivePage=tabsheet1 then
begin
gno:=edit1.Text;
gnum:=strtoint(edit2.Text);
gname:=edit3.Text;
gowner:=edit4.Text;
sno:=edit5.Text;
gprice:=strtofloat(edit7.Text);
no:=strtoint(edit6.Text);
table1.InsertRecord([no,gno,gnum,gprice,gowner,sno,datetimepicker1.date]);
table1.Active:=false;
table1.TableName:='good';
table1.Active:=true;
query1.Close;
query1.SQL.Clear;
query1.SQL.Add('select gnum from good where gno=:gno;');
if query1.Fields.Fields[0].Value=Null then
//执行if语句时程序报错"List Index out of bounds(0)"
begin
table1.InsertRecord([gno,gname,gnum,gprice,gowner,sno]);
end
else
begin
table1.SetFields([gno,gname,gnum+query1.fields[0].value,gprice,gowner,sno]);
end;
end;
form3.ShowModal;
end;
在执行到query1.Fields.Fields[0].Value程序报错"List Index out of bounds(0)"
请问如何解决?????
用TQuery和TTable控件如何在表中取值?????
procedure TForm2.Button1Click(Sender: TObject);
var
no,gnum:integer;
gprice:real;
gno,gowner,sno,gname:string;
begin
if pagecontrol1.ActivePage=tabsheet1 then
begin
gno:=edit1.Text;
gnum:=strtoint(edit2.Text);
gname:=edit3.Text;
gowner:=edit4.Text;
sno:=edit5.Text;
gprice:=strtofloat(edit7.Text);
no:=strtoint(edit6.Text);
table1.InsertRecord([no,gno,gnum,gprice,gowner,sno,datetimepicker1.date]);
table1.Active:=false;
table1.TableName:='good';
table1.Active:=true;
query1.Close;
query1.SQL.Clear;
query1.SQL.Add('select gnum from good where gno=:gno;');
if query1.Fields.Fields[0].Value=Null then
//执行if语句时程序报错"List Index out of bounds(0)"
begin
table1.InsertRecord([gno,gname,gnum,gprice,gowner,sno]);
end
else
begin
table1.SetFields([gno,gname,gnum+query1.fields[0].value,gprice,gowner,sno]);
end;
end;
form3.ShowModal;
end;
解决方案 »
- 反汇编delphi 出现 这样的字符串 System@@FileSize$qqrr15System@TFileRec
- 求报表方法,难了好长时间了,大热天日子不好过呀,哥哥姐姐用用心吧
- 用tcp传输小数据能否保证即时
- 程序运行出错如何中止?
- 请教speedButton,鼠标移进改变图片,移走也改变图片,应该在哪个事件里写?
- 在QUICKREPORT 中,如何在报表打印不满一页时,用空记录填满这一页?高分奉上!
- 在adoquery中,每当指向记录的指针发生变化时就触发某事件的代码该如何写
- 求教,程序异常关闭!
- 如何用ado连接db2数据库,都要做哪些必要的前期工作?
- 1000分救解答如何做一个类似于系统任务栏的程序
- DELPHI+ORACLE。我以SYS的身份创建了一个表,在连接指定的TABLENAME 时却看不到这个表,这是怎么回事?
- 我的查询太慢了,那位大位救命啊.
query1.SQL.Clear;
query1.SQL.Add('select gnum from good where gno=:gno;');
query1.open;
if query1.Fields.Fields[0].Value=Null then
//执行if语句时程序报错"List Index out of bounds(0)"
begin
var st:string;
....
qry.Close;
qry.SQL.Clear;
qry.SQL.Add('select * from ksid');
qry.ExecSQL;
st:=qry.Fields.Fields[1].AsString;
qry.Close;
showmessage(st);这是用来测试的,但执行到st:=qry.Fields.Fields[1].AsString;也是报错:List Index out of bounds(0)。想得头都大了!
EXECSQL是执行语句
它是执行条件呀!
ExecSQL是用来执行没有返回结果的SQL语句的如:insert into table1 (field1, field2....);
谢谢!那些所谓的参考书根本就没提到这个问题,害我差点跳楼——嘿嘿,跳到楼顶作运动而已!楼主,谢了!你的问题应该ok了吧?!