OnDel() 时 调用OnRead()时就会出现IDispatch error #3107错误,应该怎么改?void CAdoInstanceDlg::OnDel() 
{
          CString strSql="select * from UserInfo";
  BSTR bstrSQL = strSql.AllocSysString(); 
  try{    m_pRec->MoveFirst();    m_pRec->Delete(adAffectCurrent);        
}catch(_com_error e)
{
    AfxMessageBox(e.ErrorMessage());
}
    OnRead();}
void CAdoInstanceDlg::OnRead() 
{int iIndex=0;
        try
{  CString strSql="select * from UserInfo";
  BSTR bstrSQL = strSql.AllocSysString(); 
  try{  m_pRec->Open(bstrSQL,(IDispatch*)   m_pCon,adOpenDynamic,adLockOptimistic,adCmdText);
  
  m_pRec->MoveFirst();
  del=true;
  }catch(_com_error e){del=false;}
  
  if(del)
  {
  m_list.DeleteAllItems();
  }  while(!m_pRec->adoEOF)//遍历所有记录
  { 
         _variant_t UserID,UserName; 
   UserID = m_pRec->GetCollect("UserID");
   UserName = m_pRec->GetCollect("UserName");
   if(UserID.vt!=VT_NULL && UserName.vt!=VT_NULL)   {
    
    m_list.InsertItem(iIndex,(char*)_bstr_t(UserID));
    m_list.SetItemText(iIndex,1,(char *)_bstr_t(UserName));
    iIndex++;   }
  
   m_pRec->MoveNext();
  }
    }catch(_com_error e)
    {
        AfxMessageBox(e.ErrorMessage());    }
    
}

解决方案 »

  1.   

    http://www.codeproject.com/database/spcw.asp
    http://www.codeproject.com/database/mssqltutorial.asp
      

  2.   

    try{
    m_pRec->MoveFirst();
    m_pRec->Delete(adAffectCurrent);
    }  //这里的m_pRec是如何Open的?
      

  3.   

    搂主看一下:
    http://www.qhtx.net/web/CSDN/asppost11/web229154.htm
    这个帖子~~~
      

  4.   

    用AfxMessageBox( e.Description() );就可以直接看到描述了不用到处查
      

  5.   

    yes
    支持楼上的办法,强烈支持
      

  6.   

    按bololucky的办法试了一下,
    把m_pRec->Open(......)放在OnInitDialog()里就好了……
    这么说m_pRec->Open(......)不能重复执行?