components don't recognize primary key?


2004-02-18 04:33:33 PM
cppbuilder93
There are 3 tables, Person, Contact and PersonContact in a db based on MS
SQL Server 2k.
Person and Contact have identity, primary key fields PersonID and ContactID;
PersonContact sets up many-to-many relationship and has 2 fields with the
same name.
I am using TQuery with SQL statement now downgraded to "SELECT * FROM
Contact" (it had conditions, but i dropped them for testing this error to
make it look like pure table) to access Contact, some person query; I am
making a routine to enable user to add contact to person.
I was thinking of stored proc with many params, but now I want to make it
that way just for the sake of it, because it should work ;) Or at least i
think so.
What do I do?
I get input into TDB(something) components connected to query that is
referring to Contact table. Query is using cashed updates, and when user is
done, it updates the table. Everything's ok here.
However, when I try to get ContactID for my new contact (using FieldByName
from Contact query), I get zero all the time. In the table, ContactID is
inserted automatically as it should (I can see it in Enterprise manager).
I tried getting the ID immediately after Insert(), or after applying cashed
updates - it gets me zero anyway.
More than that, when I try to Refresh(), exception is thrown, telling me
that the table is not indexed so the operation is not available!
When I tried to replace TQuery with TTable, I got even weirder behavior -
even though cashed update is based on the same code, e.g. update all fields
apart from ContactID where ContactID = old one, it still throws an exception
wanting me to fill in ContactID field when I try applying updates. Why on
earth would it, when this field is Identity (autoincrement), and is the
primary key of the table?
Questions are:
Why won't IDs get read on post/on insert when they should be (I suppose),
why won't it refresh either?
And if I made wrong guesses, how do I get that damned id out the right way
to insert connection record into PersonContact?
What's the problem of TTable not wanting to auto insert increment key field?