我有两张表(student表、accounts表),我对student表中部分记录的student_money增加金额,同时,增加金额的记录同时加入到accounts表中,程序如下,但执行的速度相当慢,如何解决?
while not mydb.ADOTable_student.Eof do
begin
   mydb.ADOTable_student.Edit;
   mydb.ADOTable_student.FieldByName('student_money').AsFloat:=mydb.ADOTable_student.FieldByName('student_money').AsFloat+strtofloat(student_money.Text)*money;
   mydb.ADOTable_student.Post;
   mydb.ADOTable_student.Refresh;   mydb.ADOTable_accounts.Insert;
   mydb.ADOTable_accounts.fieldbyname('student_card').Asstring:=mydb.ADOTable_student.fieldbyname('student_card').AsString;
   mydb.ADOTable_accounts.FieldByName('student_money').AsFloat:=strtofloat(student_money.Text)*money;
   mydb.ADOTable_accounts.FieldByName('money_about').AsString:=Money_about;
   mydb.ADOTable_accounts.FieldByName('sys_name').AsString:='sys';
   mydb.ADOTable_accounts.post;
   mydb.ADOTable_accounts.refresh;   mydb.ADOTable_student.Next;
end;

解决方案 »

  1.   

    adotable_student.DisalbeControls;
    mydb.ADOTable_accounts.DisalbeControls;mydb.ADOTable_student.Edit;
    while not mydb.ADOTable_student.Eof do
    begin
       mydb.ADOTable_student.FieldByName('student_money').AsFloat:=mydb.ADOTable_student.FieldByName('student_money').AsFloat+strtofloat(student_money.Text)*money;
       mydb.ADOTable_student.Post;   mydb.ADOTable_accounts.Insert;
       mydb.ADOTable_accounts.fieldbyname('student_card').Asstring:=mydb.ADOTable_student.fieldbyname('student_card').AsString;
       mydb.ADOTable_accounts.FieldByName('student_money').AsFloat:=strtofloat(student_money.Text)*money;
       mydb.ADOTable_accounts.FieldByName('money_about').AsString:=Money_about;
       mydb.ADOTable_accounts.FieldByName('sys_name').AsString:='sys';
       mydb.ADOTable_accounts.post;   mydb.ADOTable_student.Next;
    end;
    enableControls;
    adotable_student.enableControls;
    mydb.ADOTable_accounts.enableControls;
      

  2.   

    上面倒数第三行不要..
    enableControls;
      

  3.   

    mydb.ADOTable_student.Refresh;每刷新一次,会重新从服务器取数据,偏偏ADOTable相当于Select * From Students与Select * From Accounts,你说能够不慢吗如果一定要用ADOTable添加,建议不用Refresh,如果有几千上万个学生,呵呵,慢死了或者用SQL语句添加,如果一定要实时反映出修改的结果,可以在添加后再用Sql语句根据学生ID值来取出相应的记录,那样子开销会小得多
      

  4.   

    注意看了一下,你在循环中Refresh,是完全没有必要的,每执行一次,就要取数据,不慢才怪
      

  5.   

    楼主的问题其实很简单..不要写在前台..
    数据库的STUDENT表作个触发器呀....碰到Modify时候触发修改account表..
    速度又快.也省事..