Board index » delphi » duplicate key

duplicate key

Hello,
i started to use delphi and tables.
i made a simple app using a table and a DBgrid.
whenever I try to put a duplicate key the program stops with an error
message...

Can anybody tell me how to handle the problem and in which Event ?? I am a
little bit confused on where to put the code to check for a previous
inserted key.

Thanks
ba...@poboxes.com

 

Re:duplicate key


Try the BeforePost event of the TTable.

Quote
Federico Balbi wrote:
> Hello,
> i started to use delphi and tables.
> i made a simple app using a table and a DBgrid.
> whenever I try to put a duplicate key the program stops with an error
> message...

> Can anybody tell me how to handle the problem and in which Event ?? I am a
> little bit confused on where to put the code to check for a previous
> inserted key.

> Thanks
> ba...@poboxes.com

--
Please remove the nospam from my email address when replying to messages

Re:duplicate key


You could do this:

              try
                Table1.Post;
              except
                on EDBEngineError do Table1.Cancel;
              end;

Hope this helps.
-Mike

Quote
Federico Balbi wrote:
> Hello,
> i started to use delphi and tables.
> i made a simple app using a table and a DBgrid.
> whenever I try to put a duplicate key the program stops with an error
> message...

> Can anybody tell me how to handle the problem and in which Event ?? I am a
> little bit confused on where to put the code to check for a previous
> inserted key.

> Thanks
> ba...@poboxes.com

Other Threads