首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

delphi主键重复报错,该怎么处理

2012-02-13 
delphi主键重复报错我用的是delphi,用try except想避免输入相同主键的记录时给出提示,可是第一次输入相同

delphi主键重复报错
我用的是delphi,用try except想避免输入相同主键的记录时给出提示,可是第一次输入相同主键还会执行excpt语句,提示“此记录已存在”,再次输入相同记录时,就会报错,不知道怎么回事,希望大家能够帮帮忙
下面是我的代码
adotable1.open;
adotable1.Last;
  if (combobox1.Text ='') or (combobox2.Text ='') or (combobox3.Text ='') or (edit1.Text ='') or (edit2.Text ='') or (edit3.Text ='') or (edit4.Text ='') or (edit6.Text ='') or (edit8.Text ='') or (edit9.Text ='') then
  showmessage('您输入的信息不完整!')
  else
  begin
  try
  begin
  adotable1.append;
  adotable1['年']:=combobox1.Text;
  adotable1['月']:=combobox2.Text;
  adotable1['科室']:=combobox3.text;
  adotable1['姓名']:=edit1.Text;
  adotable1['岗位系数']:=edit2.Text;
  adotable1['职称系数']:=edit3.Text;
  adotable1['基本工资']:=edit4.Text;
  adotable1['个人综合得分']:=edit6.Text;
  adotable1['扣考勤款']:=edit7.Text;
  adotable1['实发绩效工资']:=edit8.Text;
  adotable1['净领绩效工资']:=edit9.Text;
  adotable1.Post;
  edit1.setfocus;
  with ADOQuery1 do
  application.MessageBox('信息添加成功','提示',64) ;
  end;
  except
  showmessage('此记录已存在!');



  end;

  end; 



[解决办法]
...

try
adotable1.Post;
except
showmessage('此记录已存在!');
adotable1.Cancel;
exit;
end;

热点排行