这是在BDE,IBX,ADO+SQLSERVER 2000下不同的实现方案示例:
1.IBX:
procedure TData.QmanagersPostError(DataSet: TDataSet; E: EDatabaseError;
var Action: TDataAction);
begin
if copy(e.Message,1,9)='violation' then
application.MessageBox('工号重复. 请更改后重试!','错误',mb_ok+mb_iconerror)
else
if copy(e.Message,1,8)='deadlock' then
application.MessageBox('系统死锁!可能其他用户正在修改当前记录,或者当前记录已被其他用户删除。'#13'请稍后再试,或重新打开本窗口重试!','错误',mb_ok+mb_iconerror)
else
application.MessageBox(pchar('不能保存!请退出后重试!'),'提示',mb_ok+mb_iconerror);
action:=daabort;
end;
procedure TData.QmanagersUpdateError(DataSet: TDataSet; E: EDatabaseError;
UpdateKind: TUpdateKind; var UpdateAction: TIBUpdateAction);
begin
if copy(e.Message,1,9)='violation' then
application.MessageBox('工号重复. 请更改后重试!','错误',mb_ok+mb_iconerror)
else
if copy(e.Message,1,8)='deadlock' then
application.MessageBox('系统死锁!可能其他用户正在修改当前记录,或者当前记录已被其他用户删除。'#13'请稍后再试,或重新打开本窗口重试!','错误',mb_ok+mb_iconerror)
else
application.MessageBox(pchar('不能保存!请退出后重试!'),'提示',mb_ok+mb_iconerror);
updateaction:=uaabort;
end;
2.BDE
procedure TformDataModule.QfactoryUpdateError(DataSet: TDataSet;
E: EDatabaseError; UpdateKind: TUpdateKind;
var UpdateAction: TUpdateAction);
const
ekeyviol=9729;
var
iDBIError:integer;
begin
if (E is EDBEngineError) then
begin
iDBIError:=(E as EDBEngineerror).errors[0].errorcode;
case iDBIError of
ekeyviol:
begin
if application.MessageBox(pchar('编号出现重复!重复的记录将只存有一份!'+#13+'请更改编号!'),'警告',mb_iconwarning+mb_ok)=idok then
updateaction:=TUpdateAction(uaSkip);
end
end;
end;
end;
3.ADO+SQLSERVER 2000
procedure TData.ADOPostError(DataSet: TDataSet; E: EDatabaseError;
var Action: TDataAction);
begin
case adocnt.Errors.Item[0].NativeError of //ADOCNT: Tadoconnection
2627,2601:application.messagebox('编号重复,请更改后重试!','提示',mb_ok+mb_iconinformation);
515,1010:application.messagebox('请将资料填写完整!','提示',mb_ok+mb_iconinformation);
else
application.MessageBox(pchar(format('保存数据时发生错误!操作终止!'#13#13'错误代码:%d'#13'错误消息:%s',
[adocnt.Errors.Item[0].NativeError,ADOCnt.Errors.Item[0].Get_Description])),
'提示',mb_ok+mb_iconinformation);
end;
action:=daabort;
end;
解决了吗?是不是要再加分呀?