Board index » delphi » Inserting Data into Two Different Tables by querying from a single Table

Inserting Data into Two Different Tables by querying from a single Table

Hi,
    I am trying to Insert Data into Two Different Tables by querying from a
single Table,I find that query live is not going to help me,Cached Update is
also not suitable for me,because it is going to update data in single
transaction.
Is their any other way of doing it .

the options that flashing to me are
1.using a stringlist and constructing insert statements
2.have two result sets each for a bate then try update.

please tell me which is the best of doing this kind of insertion.

TIA.
kishor.
kis...@icodeindia.soft.net

 

Re:Inserting Data into Two Different Tables by querying from a single Table


Quote
"kishor" <kishor...@mailcity.com> wrote:
>Hi,
>    I am trying to Insert Data into Two Different Tables by querying from a
>single Table,I find that query live is not going to help me,Cached Update is
>also not suitable for me,because it is going to update data in single
>transaction.
>Is their any other way of doing it .

>the options that flashing to me are
>1.using a stringlist and constructing insert statements
>2.have two result sets each for a bate then try update.

>please tell me which is the best of doing this kind of insertion.

Kishor,

There's nothing to stop you from using three tables, one for fetching
data from two tables and two for updating.

Once you have the record you want to update, you will have to Locate
the record on one of the two update TTables and Edit the record there.

But you can also use cached updates with a TQuery. Here's how it
works:

A TQuery that fetches data from more than one table usually is not
updatable. That is RequestLive is automatically set to False. But you
can still update more than one table by using more than one TUpdateSQL
component.

The TQuery allows only one UpdateObject, but you can get around that
by using the Dataset property of the TUpdateSQL component. This
property is not published and so it doesn't show up on the Object
Inspector so you will have to set the property in your code.

First, leave the TQuery.UpdateObject blank. Don't use it at all.

Then, set the TUpdateSQL.Dataset property to the name of the TQuery.
Do this for both TUpdateSQL components.

Then you will have to use the TQuery.OnUpdateRecord event to do the
updates. In the event code, use the TUpdateSQL.Apply method to fire
the updates.

The nice thing about this approach is that you don't have to do any
special code to transfer data values from the TQuery to the
TUpdateSQL. Because the TUpdateSQL.Dataset is set to the TQuery, then
the TUpdateSQL component already knows about the columns in the TQUery
and will use those values to update.

If you decide to try this and have any trouble with it, don't hesitate
to post another message.

HTH

Phil Cain

--

Other Threads