数据库是access型的,用ADO联结,字段有name(sting型)、 sj(integer型),
库中数据假设如下
name sj
xc 100
xc 500
dc 30
dc 100请帮忙分析一下下面的程序的问题:
z:=0;
for m:=1 to table1.recordcount do
begin
z:=z+table1sj.value;
table1.next;
end;
此段代码运行后能够得出正确的库中所有sj字段值的和(730)。z:=0;
for m:=1 to table1.recordcount do
begin
if table1name.value=edit1.text then z:=z+table1sj.value
else
table1.next;
end;
此段代码运行后却不能得出正确的结果,假设edit1.text:=xc则此段代码运行后得出结果不是600而是400(即100加4次),百思不得其解!请高手指点!
库中数据假设如下
name sj
xc 100
xc 500
dc 30
dc 100请帮忙分析一下下面的程序的问题:
z:=0;
for m:=1 to table1.recordcount do
begin
z:=z+table1sj.value;
table1.next;
end;
此段代码运行后能够得出正确的库中所有sj字段值的和(730)。z:=0;
for m:=1 to table1.recordcount do
begin
if table1name.value=edit1.text then z:=z+table1sj.value
else
table1.next;
end;
此段代码运行后却不能得出正确的结果,假设edit1.text:=xc则此段代码运行后得出结果不是600而是400(即100加4次),百思不得其解!请高手指点!
table1.First;
z:=0;
for m:=1 to table1.recordcount do
begin
if table1name.value=edit1.text then z:=z+table1sj.value;
table1.next;//不管是不是Name=XC都要下移
end;
for m:=1 to table1.recordcount do
begin
if trim(table1name.fieldbyname('name').asstring)=trim(edit1.text) then :=z+table1sj.value;
table1.next;
end;