DBGrid Key Violation

When editing a DBGrid and entering a duplicate value into a unique key field a 'Key Violation' error occurs. Is there anyway of trapping this error to provide a more user friendly message?
roblanAsked:
Who is Participating?
 
javiertbConnect With a Mentor Commented:
You could trap the error by means of OnPostError table event. There you can chose what to do and the database error you got.

Hope this helps.
0
 
jmstoltingCommented:
..or handle the EKeyViolation exception directly :

 try
   TheTable.post;
 except
   MessageDlg('This key already exists!',mtWarning,[mbOk,0);
   TheTable.cancel; // remove the record
 end;
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.