Board index » delphi » Reading immediately after post identity field

Reading immediately after post identity field

Hi there,

I'm using Delphi 3 and MS SQL 6.5.

In last my project I using in some tables IDENTITY fields, which is also a
Primary key for the table.

In my source I use following:
  with table1 do
  begin
        Insert;      //  insert a new record in table with IDENTITY field ID
        FieldByName('name').AsString := 'My Name';    // varchar(40)
        Post;
        // server posts data into table and update field ID with next number

        Refresh;
        ShowMessage(  FieldByName('ID').AsString );
        // here I get a message with '0' every time.
end;

I think that BDE can't update Record in the buffer.
Please, if anyone solved this problem, or know what is wrong in my case any
suggestions are welcome.

Georgi Stoianov gm...@hotmail.com

 

Re:Reading immediately after post identity field


Delphi handles identity fields very poorly. It has to do with the fact
that Delphi doesn't know what the field value is after insert because
the server assigned it. Delphi does not query the server to get the last
inserted identity value.

You have no choice but to close and reopen the table. For this reason I
have stopped using identity fields.

--
Chris Cleveland
Genesee Development Group, Inc.
2000 North Racine Avenue, Suite 4100
Chicago, Illinois  60614
773.528.1700 voice, 773.528.8862 fax
http://genesee.net
cclevel...@genesee.net

Re:Reading immediately after post identity field


Just completing your response, I use IDENTITY fields but a get a value for
record throught StoredProcedure in database.

Bye,

Jean Ferreira

Quote
Chris Cleveland wrote in message <35788E7E.565D2...@genesee.net>...
>Delphi handles identity fields very poorly. It has to do with the fact
>that Delphi doesn't know what the field value is after insert because
>the server assigned it. Delphi does not query the server to get the last
>inserted identity value.

>You have no choice but to close and reopen the table. For this reason I
>have stopped using identity fields.

>--
>Chris Cleveland
>Genesee Development Group, Inc.
>2000 North Racine Avenue, Suite 4100
>Chicago, Illinois  60614
>773.528.1700 voice, 773.528.8862 fax
>http://genesee.net
>cclevel...@genesee.net

Other Threads