void CAddView::OnPopDel()
{
// TODO: 在此添加命令处理程序代码
POSITION pos = m_ListCtrl.GetFirstSelectedItemPosition();
    if (pos == NULL) AfxMessageBox(_T("没有选中的记录!"), MB_ICONEXCLAMATION);
    else
{
AdoIndex = m_ListCtrl.GetNextSelectedItem(pos);//将当前选中的索引传给主索引
if(adStateOpen==m_pRecordset->State)
{
  //CString str ;str.Format ("%d",AdoIndex);MessageBox(str);
  m_pRecordset->MoveFirst ();
  m_pRecordset->Move (AdoIndex);
  m_pRecordset->Delete (adAffectCurrent);
  m_pRecordset->Update ();
  m_ListCtrl.DeleteItem (AdoIndex);
} }
}
这是一个删除表中记录的函数,经过测试其中CtrlList和表的索引AdoIndex没有错误.第一次删除记录也没有错误,但是在第二次删除记录时显示在m_Recordset->MoveFirst()时出现错误.
这到底是怎么回事啊

解决方案 »

  1.   

    你是说第二次运行到循环里面运行movefirst出错??你捕获一下异常,看看是什么错呢!!
      

  2.   

    是啊,第二次MoveFirst出错,表不是空的还有很多记录的.
      

  3.   

    open里面的游标类型和锁定(并发)类型是怎么写的,试试用
    adOpenStatic   
    AdLockOptimistic
      

  4.   

    不是光标类型设成adOpenForwardOnly了吧,改成其他的试试