SQL UPDATE VS (CurrentRowSelected Loop) with two dbgrids


2006-08-25 06:01:23 PM
cppbuilder61
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();
}
}