我在修改一段數據時用的是以下代碼,但卻修改不了,始終在等待狀態,不報錯不退出,也沒有修改。請幫忙查看修正,謝謝!代碼如下:begin
     Query:=TADOQuery.Create(self);
     Query.Connection:=cudb01.ADOConnection1;
     Query.SQL.Text:='select * from wkprocedure ';
       with query do
          begin
            open;
            while not eof do
            begin
              if(fieldbyname('wkprocedure_no').asinteger=(pmydata(lastselnode.data))^.id)then
              begin
               try
                 cudb01.adoconnection1.begintrans;
                 query.parameters.ParamByName('wkprocedure_item').Value:=wkitem.Text;
                 query.parameters.ParamByName('wkprocedure_bp').Value:=wkbp.Text;
                 query.parameters.ParamByName('wkprocedure_name').Value:=wkname.Text;
                 cudb01.adoconnection1.committrans;
               except
                 cudb01.adoconnection1.rollbacktrans;
                 application.messagebox('修改失敗!','修改提示!');
              end;
            end;
          end;
       end;
        query.close;
        query.free;
        application.messagebox('你已成功修改!','修改提示!');
end;

解决方案 »

  1.   

    太粗心了,在剛才提問時忘記寫上query.execsql;這條執行語句,源代碼中有這條語句,但還是執行不了。
      

  2.   

    老兄~!请在循环里加一条Next
    你老抱着一条记录在处理能处理的完吗
    哈哈
      

  3.   

    呵呵,对啊,您没发现CPU使用很严重吗?
      

  4.   

    我加了NEXT還是沒反應,不退出也不報錯。
      

  5.   

    象这样的有条件的修改不如用SQL语句做了
      

  6.   

    我試著在query.execsql語句的前後和cudb01.adoconnection1.committrans;語句後都不行
      

  7.   

    返回数据集的用Open 比如用Select
    不返回数据集的用ExecSqlbegin
      Query:=TADOQuery.Create(self);
      with query do  
      begin
        Connection:=cudb01.ADOConnection1;
        SQL.Text:='select * from wkprocedure';
        open;
        while not eof do
        begin
          if(fieldbyname('wkprocedure_no').asinteger=(pmydata(lastselnode.data))^.id)then
          begin
            try
              cudb01.adoconnection1.begintrans;
              parameters.ParamByName('wkprocedure_item').Value:=wkitem.Text;
              parameters.ParamByName('wkprocedure_bp').Value:=wkbp.Text;
              parameters.ParamByName('wkprocedure_name').Value:=wkname.Text;
              cudb01.adoconnection1.committrans;
            except
              cudb01.adoconnection1.rollbacktrans;
              application.messagebox('修改失敗!','修改提示!');
            end;
          end;
          next;
        end;
      close;
      free;
      end;
      application.messagebox('你已成功修改!','修改提示!');
    end;