用TADOTable控件 怎样控制关键字重复的错误提示?(50分)

  • 主题发起人 主题发起人 小梅
  • 开始时间 开始时间

小梅

Unregistered / Unconfirmed
GUEST, unregistred user!
我知道用TTable控件可以用下列代码控制:
但TADOTable控件却不知怎办????
procedure TForm1.Table1PostError
(DataSet: TDataSet; E: EDatabaseError;
var Action: TDataAction);
begin
if (E is EDBEngineError) then
if (E as EDBEngineError).Errors
[0].Errorcode = eKeyViol then
begin
MessageDlg('出现重复记录!',
mtWarning, [mbOK], 0);
Table1.Cancel;
Abort;
end;
end;
 
procedure TForm1.ADOTable1PostError(DataSet: TDataSet; E: EDatabaseError;
var Action: TDataAction);
begin
if ADOConnection1.Errors.Item[0].NativeError=-105121349 then
begin
MessageDlg('出现重复记录!', mtWarning, [mbOK], 0);
ADOTable1.Cancel;
Abort;
end;
end;
 
Calvin 大侠你所提供的程序,我试过,不行,仍然是ODBC错误提示,程序中的错误控制没有生效。麻烦你再帮我想一想,拜托啦!!!
 
My program presented before is use Microsoft Jet OLEDB 4.0 Provider. If you use ODBC, the NativeError will be different. So the safe way to handle the KeyKiol error is get NativeError before. To get the NativeError, add the code following to the OnPostError handler:

procedure TForm1.ADOTable1PostError(DataSet: TDataSet; E: EDatabaseError;
var Action: TDataAction);
begin
MessageDlg(IntToStr(ADOConnection1.Errors.Item[0].NativeError), mtWarning, [mbOK], 0);
end;

Then you run the application, and do some "keyviol" operation. It will show the NativeError to you. After you get the NativeError, you can replace the NativeError presented in my first program with the NativeError you get.

(Because my computer cann't input GB Chinese(Big5 Only), I have to write in English and my English is so poor.)
 
'加尔文',你好,十分感激你,这个问题回答得非常好,还教了我怎样捕捉错误,我刚从烦人的VB中溜出的,所以对DELPHI不是很熟悉,还望你日后能多多关照,至于分
吗?KKK,我会给你的,这次分不算多,请笑纳。我的Email:mgq8@163.net,望谈一
谈你用DELPHI 的一些体会。再次感谢你。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部