Article View: borland.public.cppbuilder.database.ado
Article #4241Re: Database Transactions.
From: Harold Howe [TeamB]
Date: Fri, 01 Mar 2002 16:41
Date: Fri, 01 Mar 2002 16:41
31 lines
2296 bytes
2296 bytes
> I am just wondering about Database Transactions. I have a case where I need
> the ID of a newly created record in a table to be stored in another table,
> all during a transaction. Is this possible? At the moment it is not
> returning the new record's id.
>
> ie.
> DB->StartTransaction
> Table2->Insert
> ...
> Table2->Post
> id=Table2->FieldByName("ID")->AsInteger
> Table1->FieldByName("Table2ID")->AsInteger=id
> Table1->Post
> DB->Commit
If you need an ID that is assigned by the database server, you need to retrieve it
from the server somehow. I am not real familiar with table controls, but if you
insert and then post, I don't think it reloads values that were assigned on the
server. So when you look at the value of Table2->FieldByName("ID")->AsInteger, it
does not contain the value that was assigned on the server.
When I need to do this, I explicitly query the database for the most recently
assigned ID. Since I am in a transaction, I know that no one else has been able to
insert a row since I called post.
You might want to see if the table control has a method for refreshing or reloading
the record that you just posted. If it doesn't, then you may need to perform a query
to get the ID.
Harold Howe [TeamB]
http://www.bcbdev.com
Technical Details
Message-ID:
<3C7FAF3B.1BF197D3@bcbdev.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!feedme.news.mediaways.net!newsfeeds.belnet.be!news.belnet.be!news.tele.dk!small.news.tele.dk!209.98.3.206!news-out.visi.com!hermes.visi.com!out.nntp.be!propagator-SanJose!in.nntp.be!newsfeed01.tsnz.net!newsfeeds.ihug.co.nz!ihug.co.nz!dnewsReferences:
<3c7c1dfc_2@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10698b,2ae92d6da780eff0 X-Google-Attributes: gid10698b,public X-Google-ArrivalTime: 2002-03-01 08:42:47 PST Message-ID: <3C7FAF3B.1BF197D3@bcbdev.com> Date: Fri, 01 Mar 2002 10:41:31 -0600 From: "Harold Howe [TeamB]" <hhowe@bcbdev.com> X-Mailer: Mozilla 4.03 [en] (WinNT; I) MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.database.ado Subject: Re: Database Transactions. References: <3c7c1dfc_2@dnews> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 12.216.65.188 X-Trace: dnews 1015000831 12.216.65.188 (1 Mar 2002 08:40:31 -0800) Lines: 31 Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!feedme.news.mediaways.net!newsfeeds.belnet.be!news.belnet.be!news.tele.dk!small.news.tele.dk!209.98.3.206!news-out.visi.com!hermes.visi.com!out.nntp.be!propagator-SanJose!in.nntp.be!newsfeed01.tsnz.net!newsfeeds.ihug.co.nz!ihug.co.nz!dnews