title: How to check if row with such id presents in db in Access DB by MFC app
body: <p>I have the following window:</p>
  
  <p><a href="https://i.stack.imgur.com/ORMsO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ORMsO.png" alt="enter image description here"></a></p>
  
  <p>By this window I can insert new row to DB. But how can I check if row with such ID exists, as when I insert the row with the same ID my app crashes. Here's the code:</p>
  
  <pre><code>void CMikhailovskiiDBView::OnRecordAdd()
  {
      // TODO: Add your command handler code here
      m_pSet-&gt;AddNew();
      m_bAdding = TRUE;
      CEdit* pCtrl = (CEdit*)GetDlgItem(IDC_LibraryID);
      int result = pCtrl-&gt;SetReadOnly(FALSE);
      UpdateData(FALSE);
  }
  </code></pre>
  
  <p>By this method I am giving an access to ID edit as when I work with data (not insert row) this edit is read only. And here's the code of inserting to db method:</p>
  
  <pre><code>BOOL CMikhailovskiiDBView::OnMove(UINT nIDMoveCommand)
  {
      if (m_bAdding) {
          m_bAdding = FALSE;
          UpdateData(TRUE);
          if (m_pSet-&gt;CanUpdate()){
              m_pSet-&gt;Update();
              m_pSet-&gt;Requery();
              UpdateData(FALSE);
              CEdit* pCtrl = (CEdit*)GetDlgItem(IDC_LibraryID);
              pCtrl-&gt;SetReadOnly(TRUE);
              return TRUE;
          }
      }
      else {
          return CRecordView::OnMove(nIDMoveCommand);
      }
  }
  </code></pre>
  
  <p>So, I even don't understand where I should add validation for ID. I will appreciate any help. Thanks in advance!</p>