你在提交数据之前try
.............
  Post;//
except
  ShowMessage("can not insert duplicate key")
end;

解决方案 »

  1.   

    procedure TForm1.Table1PostError(DataSet: TDataSet;
      E: EDatabaseError; var Action: TDataAction);
    begin
      if E is EdbEngineError then
        if (E as EdbEngineError).Errors[0].ErrorCode = KEYVOL then
        begin
           Application.MessageBox('主键重复,请重新定义','错误',MB_OK+MB_ICONINFORMATION);
           Table1.Cancel;
        end;
    这样保证可以!!
    end;
      

  2.   

    //错误码:9729--主键;9732--不能为空;9733--外键约束
    procedure TForm1.Table1PostError(DataSet: TDataSet;
      E: EDatabaseError; var Action: TDataAction);
    begin
      if E is EdbEngineError then
        if (E as EdbEngineError).Errors[0].ErrorCode = 9729 then
        begin
           Application.MessageBox('主键重复,请重新定义','错误',MB_OK+MB_ICONINFORMATION);
           Table1.Cancel;
        end;