我的在数据据有一个表ka表里面只有一个字段word字段为主码,我用如下代码插入数据(用ado连接数据库)
try
{     
   m_pRecordset->AddNew ();
   m_pRecordset->PutCollect("word", _variant_t(word));
   m_pRecordset->Update ();
}
catch(...)
{
}      
当主码没重复时,没什么问题,当主码有重复时,程序崩溃,
我想让他有有重复时不做任何处理,要怎么做

解决方案 »

  1.   

    重复就是我己经插入了数据ab再次插入ab程序就崩溃了
      

  2.   


    catch(_com_error &e)catch 这样写就不会出错了。
      

  3.   

    同上
    catch,什么都不处理
      

  4.   

    我改成这样,还是会崩溃
    try
    {
          m_pRecordset->AddNew ();
           m_pRecordset->PutCollect("word", _variant_t(word));
           m_pRecordset->Update ();
    }
    catch(_com_error &e)
    {
    }
    {
    }
      

  5.   

    还崩溃??
    那就catch(...){}
      

  6.   

    我原来就是
    catch(...)
    {
    }
    还有其它的方法吗?
    如果实在不行,只有我自己写个类实现这个功能了
      

  7.   

    很奇怪
    那就再插入之前先检查一下吧 select from where 
      

  8.   

    先用一个函数查询一下,如果已存在就不要进行插入和添加了,但可以执行编辑和删除动作。BOOL WordIsExist(LPCTSTR strWord)
    {
    CString str,strSQL;
    str = strWord;
    strSQL.Format(select * from ka where word='%s'",str);
    ...
    if(m_pRecordset->GetRecordCount() > 0)
       return TRUE;
    else
       return FALSE;
    }