Board index » delphi » DATABASE KEY VIOLATION ERROR - HELP !

DATABASE KEY VIOLATION ERROR - HELP !

Hi there,

I created a simple Database where I have 1 key.  The Keys are manually
entered and the chances of entering a duplicate are very likely.

My DB crashes and alerts me of this KEY VIOLATION error.  I would
like the user to be able to re-enter the value as many times as needed
before a crash takes place.  

How would I implement the coding to do this ?  

Thank you for helping out !

Regards

Anton

 

Re:DATABASE KEY VIOLATION ERROR - HELP !


On Sat, 17 Feb 1996 11:11:31 GMT, cldp...@mail.global.co.za (Anton

Quote
Grobbelaar) wrote:
>I created a simple Database where I have 1 key.  The Keys are manually
>entered and the chances of entering a duplicate are very likely.

>My DB crashes and alerts me of this KEY VIOLATION error.  I would
>like the user to be able to re-enter the value as many times as needed
>before a crash takes place.  

>How would I implement the coding to do this ?  

There are a number of possible approaches you might take to address such a
situation. Ask 1,001 programmers, and you will likely get 1,001 answers
<grin>.

One way would be to use a second TTable component, connected to the same
table, and search that table for the key value prior to an attempt to post
the record. You could do this in a procedure for a variety of different
events. An event based on the posting of the record as a whole is
BeforePost, in which you could call the Abort procedure to stop the post of
the record if the search in the second table yields a find. Another event
is based on the control used to edit the key value, the OnExit event. this
event is triggered when aan attempt is made to move focus to another
control. If you search the second table in this event and find the key
value already exists, you can optionally display a message and then set
focus back to the key field's associated control.

Another means would be to use exception handling. Fields in an exception
object will tell what caused the exception, allowing you to
programmatically take action based on the type and nature of the exception.

**************************************************************************
Steve Koterski                  "Results! Why, man, I have gotten a lot of
Product Group Manager           results. I know several thousand things
Delphi Technical Support        that won't work."
Borland International, Inc.                    -- Thomas Edison, 1847-1931

Re:DATABASE KEY VIOLATION ERROR - HELP !


Key violation should not cause crash, unless posting related events
contain some bugs, excessive recursion etc, You seem to have a serious
problem here.

Other Threads