Board index » delphi » 'Record/Key Deleted' Exception

'Record/Key Deleted' Exception

Hi,

I'm working with MS SQL 6.0. + Delphi C/S 2.0 + Borland SQL Links.

The problem I have is :

   when I'm using TTable for inserting
   new record into the table on SQL,
   exception 'Record\Key Deleted' generated by Delphi.

Would you mind to tell me how to solve this problem.

 

Re:'Record/Key Deleted' Exception


Quote
"Novoselov Konstantin" <n...@povv.chel.su> wrote:
>Hi,
>I'm working with MS SQL 6.0. + Delphi C/S 2.0 + Borland SQL Links.
>The problem I have is :
>   when I'm using TTable for inserting
>   new record into the table on SQL,
>   exception 'Record\Key Deleted' generated by Delphi.
>Would you mind to tell me how to solve this problem.

If this is of any help to you, I had the same problem with D1, Access
2.0 and ODBC. When inserting records for the second time I got the
above error message. I then noticed the I had to call Table1.Refresh
to reload all the records after a single insert. This made it the
program very slow and so I stopped using TTables. With TQuerys I have
had (almost) no problems. Also, the performance is better.

Regards,

Jani J?rvinen
Helsinki Finland
ja...@xgw.fi

Re:'Record/Key Deleted' Exception


Quote
>    when I'm using TTable for inserting
>    new record into the table on SQL,
>    exception 'Record\Key Deleted' generated by Delphi.

Hi,  I recently encountered the same problem.  Chances are the table you're
using is using a trigger generated value in a field during the post event
and your TTable is using an index on that field.  With InterBase the record
gets posted successfully: the error occurs because the change in the index
field value causes the record to disappear from under the BDE's feet when
Delphi attempts to reread the record after posting.

The advice given in a TI doc on Borland Online suggests that you either (a)
not use triggers to insert values in the table (now isn't that useful?!) or
(b) use an index on the table that doesn't include the triggered field.  In
addition, use TTable.Refresh in the TTable.AfterPost event to get the
refresh the BDE buffer with the values inserted into the record by the
trigger(s).

Also, I discovered that TTable.Refresh also allowed me to display to the
user the unique key value generated by the trigger during posting.  You
need to manually call the Refresh method (in addition to the
TTable.AfterPost event) in your procedure where you try to retrieve the
value.

I recommend you get the same TI doc yourself - browse the library for the
'Record/Key Deleted' Exception.  The TI refers to Delphi 1 but applies
equally well to Delphi 2.

Hope this helps,

Boris Bosnjak
Software Craftsman
DreamQuest Canada

Re:'Record/Key Deleted' Exception


Hi,

DreamQuester <d...@interlog.com> schrieb im Beitrag
<01bbb0bd$8bb4a580$a4436...@dq.interlog.com>...

Quote
> >    when I'm using TTable for inserting
> >    new record into the table on SQL,
> >    exception 'Record\Key Deleted' generated by Delphi.

> The advice given in a TI doc on Borland Online suggests that you either
(a)
> not use triggers to insert values in the table (now isn't that useful?!)
or
> (b) use an index on the table that doesn't include the triggered field.
In
> addition, use TTable.Refresh in the TTable.AfterPost event to get the
> refresh the BDE buffer with the values inserted into the record by the
> trigger(s).

> I recommend you get the same TI doc yourself - browse the library for the
> 'Record/Key Deleted' Exception.  The TI refers to Delphi 1 but applies
> equally well to Delphi 2.

I had this problem, too. The reason was indeed a trigger which
had to count to the next index value. This is my workaround:

procedure TDBMod_Auto.tbl_MotorenAfterInsert(DataSet: TDataSet);
begin
    {Open SQL-Query for the last index [primary key] on the motor table}
    DBMod_Auto.maxMotoren.Open;
    {increment index}
    frmMotoren.edMotorenID.Text :=
IntToStr(StrToInt(DBMod_Auto.maxMotoren.Fields[0].AsString) + 1);
    {Close SQL-Query}
    DBMod_Auto.maxMotoren.Close;
    {Set focus to next entry field}
    frmMotoren.edLeistung.SetFocus
end;

The Query is

SELECT max(MotorID) FROM Motoren;

It works well for me.

Bernhard

--
----------------------------------------------------------------------------
---
Bernhard Husch
Reichnerweg 45, D-12305 Berlin
phone +49 30 742 92 08

- Show quoted text -

Quote

Other Threads