xiaowind,不对吧?
e.message='Key violation.'
e.message会只是一个单纯的Key violation?用errorcode吧
const
eKeyViol = 9729;
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;
关于其他error的说明:
A complete listing of the database errorcodes is found in the
DBIErrs.Int file in the Delphi/Doc directory or in the IDAPI.h
file in the Borland Database Engine.
Database errors are defined by category and code. Here's a sample:
{ ERRCAT_INTEGRITY }
ERRCODE_KEYVIOL = 1; { Key violation }
ERRCODE_MINVALERR = 2; { Min val check failed }
ERRCODE_MAXVALERR = 3; { Max val check failed }
ERRCODE_REQDERR = 4; { Field value required }
ERRCODE_FORIEGNKEYERR = 5; { Master record missing }
ERRCODE_DETAILRECORDSEXIST = 6; { Cannot MODIFY or DELETE this Master record }
ERRCODE_MASTERTBLLEVEL = 7; { Master Table Level is incorrect }
ERRCODE_LOOKUPTABLEERR = 8; { Field value out of lookup tbl range }
ERRCODE_LOOKUPTBLOPENERR = 9; { Lookup Table Open failed }
ERRCODE_DETAILTBLOPENERR = 10; { 0x0a Detail Table Open failed }
ERRCODE_MASTERTBLOPENERR = 11; { 0x0b Master Table Open failed }
ERRCODE_FIELDISBLANK = 12; { 0x0c Field is blank }
The constant for the base category is added to these constants to represent
a unique DBI errorcode;
DBIERR_KEYVIOL = (ERRBASE_INTEGRITY + ERRCODE_KEYVIOL);
DBIERR_REQDERR = (ERRBASE_INTEGRITY + ERRCODE_REQDERR);
DBIERR_DETAILRECORDSEXIST = (ERRBASE_INTEGRITY + ERRCODE_DETAILRECORDSEXIST);
DBIERR_FORIEGNKEYERR = (ERRBASE_INTEGRITY + ERRCODE_FORIEGNKEYERR);
The ERRBASE_INTEGRITY value is $2600 (Hex 2600) or 9728 decimal.
Thus, for example, the errorcode for keyviol is 9729
for master with details is 9734.
*)
来源于delphi下demos/db/dberrors/的例子,那种解决方法不错啊,为什么还要讨论
来讨论去?