我用的是SQL数据库,对表进行添加操作,如果添加的两条记录一模一样,SQL就会报错。如何能捕捉到这个错误,我应该怎么写代码》

解决方案 »

  1.   

    query.sql.text='select * from table where id='''+edit1.text+''' '
    query.open;
    if  not query.Eof 
    then
    showmessage('this is also exist')
      

  2.   

    query.sql.text='select * from table where id='''+edit1.text+''' '
    query.open;
      if query.RecordCount>0 then
         application.MessageBox('记录已经存在','',mb_ok+mb_iconinformation)
      

  3.   

    1.设上主键
    2.  在postError中
      Action := daAbort;
      if Pos('PRIMARY KEY', E.Message) <> 0 then
      begin
        Application.MessageBox('主键冲突,检查后再输入', '提示:',    MB_OK      +      MB_ICONINFORMATION);
      end;