Recent

Author Topic: Problem nested while i have problem with my code. it can't update from command  (Read 1682 times)

toem1234

  • Newbie
  • Posts: 2
Problem  nested while  i have problem with my code. it can't update from command

OR  where? example nested while.   Thank you

Code: [Select]
procedure TForm6.Update_Select_Income;
begin
   while not Select_Income.EOF do
    begin
      while not query.EOF do
      begin
        if ((Select_Income.FieldByName('income_category').AsString) = (query.FieldByName('income_category_name').AsString))  then
        begin
           Update_Income.Params.ParamValues['income_order']:= Select_Income.FieldByName('income_order').AsString;
           Update_Income.Params.ParamValues['income_category']:= query.FieldByName('income_category_id').AsString;
           Update_Income.ExecSQL;
           Update_Income.Close;
        end;
        query.Next;
      end;
      Select_Income.Next;
    end;
   ShowMessage('Success!');
end; 

GetMem

  • Hero Member
  • *****
  • Posts: 3884
Code: [Select]
procedure TForm6.Update_Select_Income;
begin
   Select_Income.First; //make sure, it's the first record
   while not Select_Income.EOF do
    begin
      query.First;  //make sure, it's the first record
      while not query.EOF do
      begin
        if ((Select_Income.FieldByName('income_category').AsString) = (query.FieldByName('income_category_name').AsString))  then
        begin
           Update_Income.Close;
           Update_Income.Params.BeginUpdate;
           Update_Income.Params.ParamValues['income_order']:= Select_Income.FieldByName('income_order').AsString;
           Update_Income.Params.ParamValues['income_category']:= query.FieldByName('income_category_id').AsString;
           Update_Income.Params.EndUpdate;
           Update_Income.ExecSQL;           
        end;
        query.Next;
      end;
      Select_Income.Next;
    end;
    Tansaction.CommitRetaining; //you need a transaction, to commit the changes
   ShowMessage('Success!');
end; 

If the params are correct this should work! Any exception raised? ShowMessage is displayed?

toem1234

  • Newbie
  • Posts: 2
 i tested. it working Thank so much
Code: [Select]
procedure TForm6.Update_Select_Income;
begin
  Select_Income.First; //make sure, it's the first record
  while not Select_Income.EOF do
   begin
     query.First;  //make sure, it's the first record
     while not query.EOF do
     begin
       if ((Select_Income.FieldByName('income_category').AsString) = (query.FieldByName('income_category_name').AsString))  then
       begin
          Update_Income.Close;
          Update_Income.Params.BeginUpdate;
          Update_Income.Params.ParamValues['income_order']:= Select_Income.FieldByName('income_order').AsString;
          Update_Income.Params.ParamValues['income_category']:= query.FieldByName('income_category_id').AsString;
          Update_Income.Params.EndUpdate;
          Update_Income.ExecSQL;
       end;
       query.Next;
     end;
     Select_Income.Next;
   end;
   Select_Income.CommitUpdates;   //.CommitRetaining; //you need a transaction, to commit the changes
  ShowMessage('Success!');
end;
     

 

TinyPortal © 2005-2018