> I insert 1 record into the first table with
>
[snip]
> adoquery1.FieldByName('PA_id').asstring:=''; // TBA, maybe
> adoquery1.Post;
> Log('Link ID '+adoquery1.FieldByName('id').AsString]);
>
> And then I insert some other records into the 2nd table, which I link
> to the first table with the "id" field I log above.
>
> The problem is every now and then the id field comes back with
> something really out of sequence [snip]
It seems that the table you are inserting into has an identity as the
primary key. Behind the scenes, ADO uses @[EMAIL PROTECTED]
to return the
identity
that was inserted, into the TField linked to it, but it will return the
last identity inserted as a result of your insert. If you have some sort
of trigger on the table in question, and that trigger inserts into another
table that also has an identity, you'll get this value back! E.g. If a
trigger is inserting into some sort of auditing table. So I suspect this
is what is happening in your case.
> The output of my log procedure shows things like
> Link ID 222019
> Link ID 222020
> Link ID 9719
> Link ID 222022
> Link ID 222023
>
> Sure enough, when I try to find 9719 in the database, it either
> doesn't exist, or it's a really old record from days ago. If I look at
> 222021 (which I don't have in my log), sure enough I find the record I
> inserted, which was re****ted as being 9719.
>
> Any ideas? It's really doing my head in.
>
> Dodgy.
ADO should really use Scope_Identity() or Ident_current('THE_TABLE_NAME')
to return the correct identity. So you'll have to do this yourself and
use
this as the link ID instead.
Hopefully your head isn't done in anywmore.
Grent


|