procedure Tform1.adodatasetposterror(..); var theerrors:errors theerror:error; i:integer; begin theerrors:=adoconnection1.errors; for i:=0 to theerrors.count-1 do begin theerror:=theerrors.item[i]; listbox1.items.add('error number:'+inttostr(theerror.number)); listbox1.items.add('error source:'+theerror.source); ........ end; end; 这是我在书上抄的一个例子,可以看出与ado有关的错误被封装到了adoconnection.errors中,其它错误仍然可以通过E得到
ado 一样可以拉返回数据库的错误编码在POSTERROR事件中可以捕捉, 下面的是我们工程的部分代码。SQLSERVER 2000库 procedure TEmpInfoFrm.EmpDataSetPostError(DataSet: TDataSet; E: EDatabaseError; var Action: TDataAction); Var ADOErrors:Errors; begin Action:=daAbort; adoErrors:=mainform.ado_connect.Errors; //Showmessage(IntToStr(adoErrors.Item[0].Number)); if adoErrors.Item[0].Number=-2147217873 then Application.MessageBox(Pchar('员工编码:'+DataSet.FieldByName('cEmpCode').asString+'重复'),'保存记录',MB_OK+MB_ICONINFORMATION); if adoErrors.Item[0].Number=-2147217864 then begin Application.MessageBox('本记录已被其他用户修改','保存记录',MB_OK+MB_ICONINFORMATION); EmpDataSet.Cancel; EmpDataSet.Refresh; end;上分吧!
来捕获。
var theerrors:errors
theerror:error;
i:integer;
begin
theerrors:=adoconnection1.errors;
for i:=0 to theerrors.count-1 do
begin
theerror:=theerrors.item[i];
listbox1.items.add('error number:'+inttostr(theerror.number));
listbox1.items.add('error source:'+theerror.source);
........
end;
end;
这是我在书上抄的一个例子,可以看出与ado有关的错误被封装到了adoconnection.errors中,其它错误仍然可以通过E得到
下面的是我们工程的部分代码。SQLSERVER 2000库
procedure TEmpInfoFrm.EmpDataSetPostError(DataSet: TDataSet;
E: EDatabaseError; var Action: TDataAction);
Var
ADOErrors:Errors;
begin
Action:=daAbort;
adoErrors:=mainform.ado_connect.Errors;
//Showmessage(IntToStr(adoErrors.Item[0].Number));
if adoErrors.Item[0].Number=-2147217873 then
Application.MessageBox(Pchar('员工编码:'+DataSet.FieldByName('cEmpCode').asString+'重复'),'保存记录',MB_OK+MB_ICONINFORMATION);
if adoErrors.Item[0].Number=-2147217864 then
begin
Application.MessageBox('本记录已被其他用户修改','保存记录',MB_OK+MB_ICONINFORMATION);
EmpDataSet.Cancel;
EmpDataSet.Refresh;
end;上分吧!
ERROR本身就是ADO所包含的一个对象,
先看看ADO有关的书吧