🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.database.ado
Article #357

SQL UPDATE VS (CurrentRowSelected Loop) with two dbgrids

#357
From: 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();
   }
}
Technical Details
Message-ID: <1156500083.781850.100450@74g2000cwt.googlegroups.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!postnews.google.com!74g2000cwt.googlegroups.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10698b,8d3e570fd4be7d0e,start
X-Google-Attributes: gid10698b,public
X-Google-Language: ENGLISH,ASCII-7-bit
Path: arc1-ca.pugleaf.net!g2news2.google.com!postnews.google.com!74g2000cwt.googlegroups.com!not-for-mail
From: "Alien_SM" <Alien.JAvdT@gmail.com>
Newsgroups: borland.public.cppbuilder.database.ado
Subject: SQL UPDATE VS (CurrentRowSelected Loop) with two dbgrids
Date: 25 Aug 2006 03:01:23 -0700
Organization: http://groups.google.com
Lines: 89
Message-ID: <1156500083.781850.100450@74g2000cwt.googlegroups.com>
NNTP-Posting-Host: 196.2.124.252
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
X-Trace: posting.google.com 1156500089 19803 127.0.0.1 (25 Aug 2006 10:01:29 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Fri, 25 Aug 2006 10:01:29 +0000 (UTC)
User-Agent: G2/0.2
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.6) Gecko/20060728 Firefox/1.5.0.6,gzip(gfe),gzip(gfe)
X-HTTP-Via: 1.1 jnb-cache03 (NetCache NetApp/6.0.2P1D1)
Complaints-To: groups-abuse@google.com
Injection-Info: 74g2000cwt.googlegroups.com; posting-host=196.2.124.252;
   posting-account=ZWxgpw0AAAB88ez1CMV2VgyXCqWnJ4Ce