Board index » delphi » Cashed Updates for a query joining two tables

Cashed Updates for a query joining two tables

I have a query joining two tables that I need to be Cash Update.  I
created two separate TUpdateSQL, one for each table.  I left the
UpdateObject property of the query to be blank and in code I do the
following:
UpdateSQL1.Dataset := MyQuery;
UpdateSQL2.Dataset := MyQuery;
I know that I need an OnUpdateRecord Event for my query to execute the
updates using either ExecSQL or Apply and then set the UpdateAction to
uaApplied.  But I am not sure how to do that having two TUpdateSQL's
since I would assume that each record in my query (that includes fields
from two tables) should be posted at once.
I would really appreciate it if some body can give me an example of how
the code in the OnUpdateRecord event handler would look like.
Thanks in advance.
Nina.
 

Re:Cashed Updates for a query joining two tables


On Fri, 26 Mar 1999 11:54:38 -0600, Nina Gaspar <ngas...@rlc.cc.il.us>
wrote:

Quote
>I have a query joining two tables that I need to be Cash Update.  I
>created two separate TUpdateSQL, one for each table.  I left the
>UpdateObject property of the query to be blank and in code I do the
>following:
>UpdateSQL1.Dataset := MyQuery;
>UpdateSQL2.Dataset := MyQuery;
>I know that I need an OnUpdateRecord Event for my query to execute the
>updates using either ExecSQL or Apply and then set the UpdateAction to
>uaApplied.  But I am not sure how to do that having two TUpdateSQL's
>since I would assume that each record in my query (that includes fields
>from two tables) should be posted at once.
>I would really appreciate it if some body can give me an example of how
>the code in the OnUpdateRecord event handler would look like.

From the online help...

--------------------------------------------------------------------------
When more than one base table referenced in the update dataset needs to be
updated, you need to use multiple update objects: one for each base table
updated. Because the dataset components UpdateObject only allows one
update object to be associated with the dataset, you must associate each
update object with the dataset by setting its DataSet property to the name
of the dataset. The DataSet property for update objects is not available at
design time in the Object Inspector. You can only set this property at
runtime.

  UpdateSQL1.DataSet := Query1;
  UpdateSQL2.DataSet := Query1;

The update SQL statements in the update object are not automatically
executed when the update datasets ApplyUpdates method is called. To update
records, you must supply a handler for the dataset components
OnUpdateRecord event and call the update objects ExecSQL or Apply method.
This invokes the update object for each record that requires updating.
In the handler for the datasets OnUpdateRecord event, the minimum actions
that you need to take in that handler are:

Calling the update objects SetParams method (if you later call ExecSQL).
        Executing the update object for the current record with ExecSQL or
Apply.
        Setting the event handlers UpdateAction parameter to uaApplied.

You may optionally perform data validation, data modification, or other
operations that depend on each records update.

Note:   It is also possible to have one update object associated with the
dataset using the dataset components UpdateObject property, and the second
and subsequent update objects associated using their DataSet properties.
The first update object is executed automatically on calling the dataset
components ApplyUpdates method. The rest need to be manually executed.
--------------------------------------------------------------------------

So, in the OnUpdateRecord event handler, you need to call the Apply method
once for *each* TUpdateSQL component used.

//////////////////////////////////////////////////////////////////////////
Steve Koterski                    "My problem lies in reconciling my gross
Technical Publications            habits with my net income."
INPRISE Corporation                             -- Errol Flynn (1909-1959)
http://www.borland.com/delphi

Other Threads