🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.database.ado
1 messages
1 total messages Started by Alien_SM Fri, 25 Aug 2006 10:01
SQL UPDATE VS (CurrentRowSelected Loop) with two dbgrids
#357
Author: Alien_SM
Date: Fri, 25 Aug 2006 10:01
88 lines
3693 bytes
Ok here is the senario:

I have two dbrids called
   TDBGrid *DBGItemsLeft;
   TDBGrid *DBGItemsRight;
They have data sets assosiated with them:
   TADODataSet *DSeItemsRight;
   TADODataSet *DSeItemsLeft;

There is two speed buttons called
SBMoveR
SBMoveL

So what the moveR button must do is add the highlighted rows in the
left grid to the right and moveL Removes the highlighted rows in the
right grid.  I am using Next and EOF to iterate thru the rows and scan
currentRowSelected and then set a field in the database.

Is this the right way to do this type of thing, it works but is not as
fast as I would like. I already have the cursors set to server to speed
it up, at the moment there is only 2000 items in the DB ("Access 2002"
DB, I know but its not my choice) and this will grow more in the
future.

I also have a move all left and all right that uses a ADOCommand and
SQL UPDATE statement.  This is fast in comparison with the Iteration
versions.

So here  is the Question can pull a simular trick to move only the
highlighted rows, using SQL UPDATE?

Here is the listing of the on click event:

void __fastcall TMainForm::SBMoveLClick(TObject *Sender)
{
   DSeItemsRight->DisableControls();
   DSeItemsLeft->DisableControls();
   DSeItemsRight->First();
   __try
   {
       while(!DSeItemsRight->Eof)
       {
         if(DBGItemsRight->SelectedRows->CurrentRowSelected)
         {
            DSeItemsRight->Edit();
            DSeItemsRightSelected->AsInteger = 0;
            DSeItemsRight->Post();
         }
         else
         {
            DSeItemsRight->Next();
         }
       }
   }
   __finally
   {
      DSeItemsLeft->Refresh();
      DSeItemsLeft->EnableControls();
      DSeItemsRight->EnableControls();
   }
}
//---------------------------------------------------------------------------

void __fastcall TMainForm::SBMoveRClick(TObject *Sender)
{
   DSeItemsRight->DisableControls();
   DSeItemsLeft->DisableControls();
   DSeItemsLeft->First();
   __try
   {
       while(!DSeItemsLeft->Eof)
       {
         if(DBGItemsLeft->SelectedRows->CurrentRowSelected)
         {
            DSeItemsLeft->Edit();
            DSeItemsLeftSelected->AsInteger = 1;
            DSeItemsLeft->Post();
         }
         DSeItemsLeft->Next();
       }
   }
   __finally
   {
      DSeItemsRight->Refresh();
      DSeItemsLeft->EnableControls();
      DSeItemsRight->EnableControls();
   }
}
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads