const
eKeyViol = 9729;
在table的onposterror事件中写如下代码
procedure TDM.CustomerPostError(DataSet: TDataSet;
E: EDatabaseError; var Action: TDataAction);
begin
if (E is EDBEngineError) then
if (E as EDBEngineError).Errors[0].Errorcode = eKeyViol then
begin
MessageDlg('Unable to post: Duplicate Customer ID.', mtWarning, [mbOK], 0);
Abort;
end;
end;