dm.Command.CommandText := ' begin tran '
      + ' delete from data '
      + ' delete from temp_data '
      + ' commit tran ';
    dm.Command.Execute;
  OpenDial := TopenDialog.Create(self);
  while  bStop<>1 do
  begin
    OpenDial.Filter := 'Text files (*.txt)|*.TXT';
    if OpenDial.Execute then
      fileName := OpenDial.FileName
    else
      break;
    if fileName <> '' then
      InsertData(fileName, '1');
   if MessageDlg('還有掃描檔嗎?',mtConfirmation, [mbYes, mbNo], 0) = mrYes then//這個地方執行後,直接跳出while語句,為什麼?
   begin
      bStop := 0;
      continue;
    end else
    begin
      bStop := 1;
      break;
    end;
  end;
 
  with dm do //
  begin
    dm.Command.CommandText := ' INSERT INTO DATA (BM_DM,TM,YD_RY,SL)  '
      + ' SELECT BM_DM,TM,YD_RY,SUM(CONVERT(INTEGER,SL)) '
      + ' FROM TEMP_DATA '
      + ' GROUP BY BM_DM,TM,YD_RY ';
    dm.Command.Execute;
  end;
  

解决方案 »

  1.   

    找到原因了,
    不能TDM中建
    OpenDial := TopenDialog.Create(self);
      

  2.   


     dm.Command.CommandText   :=   "   begin   tran   " 
                +   "   delete   from   data   " 
                +   "   delete   from   temp_data   " 
                +   "   commit   tran   "; 
            dm.Command.Execute; 
        OpenDial   :=   TopenDialog.Create(self); 
        while     bStop < >1   do 
        begin 
            OpenDial.Filter   :=   "Text   files   (*.txt) ¦*.TXT "; 
            if   OpenDial.Execute   then 
                fileName   :=   OpenDial.FileName 
            else 
                break; 
            if   fileName   < >   " "   then 
                InsertData(fileName,   "1 "); 
          if   MessageDlg( "還有掃描檔嗎? ",mtConfirmation,   [mbYes,   mbNo],   0)   =   mrYes   then//這個地方執行後,直接跳出while語句,為什麼? 
          begin 
                bStop   :=   0; 
                continue; 
            end   else 
            begin 
                bStop   :=   1; 
                break; 
            end; 
        end; 
      
        with   dm   do   // 
        begin 
            dm.Command.CommandText   :=   "   INSERT   INTO   DATA   (BM_DM,TM,YD_RY,SL)     " 
                +   "   SELECT   BM_DM,TM,YD_RY,SUM(CONVERT(INTEGER,SL))   " 
                +   "   FROM   TEMP_DATA   " 
                +   "   GROUP   BY   BM_DM,TM,YD_RY   "; 
            dm.Command.Execute; 
        end;