try{
_RecordsetPtr m_pRs; CString bstrShopingCartSQL="select * from ShoppingCart";   
m_pRs.CreateInstance(__uuidof(Recordset));
m_pRs->CursorLocation = adUseClient;
m_pRs->Open((LPCTSTR)bstrShopingCartSQL, (LPCTSTR)m_strConnection,adOpenDynamic,adLockOptimistic, adCmdText); CString CstrCookie;
CstrCookie.Format("user_name='%s' and shop_='0'",strCookie);
m_pRs->Filter=_variant_t(CstrCookie); long Ishop=1;
for(int i=1;((i<=m_pRs->RecordCount)&&(!m_pRs->EndOfFile));i++)
{
m_pRs->PutCollect("shop_", _variant_t(Ishop));
m_pRs->Update(); m_pRs->MoveNext();
}
m_pRs->Close();
m_pRs.Release();
}
//代码如上,原意是要更改数据库中user_name='%s' and shop_='0'的所有数据,但是现在只能更新一部分,并不能全部更新,很是奇怪,不知道为什么,请高手指点..@@!

解决方案 »

  1.   

    直接用ado command执行下面这个语句就行了,何必写得这么麻烦
    "update ShoppingCart set shop_='1' where user_name='%s'"
      

  2.   

    CString bstrShopingCartSQL="select * from ShoppingCart";
    bstrShopingCartSQL.Format(bstrShopingCartSQL+"user_name='%s' and shop_='0'",strCookie");
    ...
    直接这样不行吗?找一下没更新的那部分的规律,再分析可能是由什么原因导致的。不行的话直接用1楼的方法,简单实用
      

  3.   

    这句话的问题.i <=m_pRs->RecordCount你的打开方式要使用adOpenForwardOnly才能正确得到行数!你可以把那句话去掉就OK了
      

  4.   

    直接用sql语句,直接Updtae
    CString str;
    str.Format(_T("update ShoppingCart set shop_='1' where user_name=\'%s\'"),strCookie);
      

  5.   

    直接执行SQL语句
    update ShoppingCart set shop_='1' where user_name='%条件'
      

  6.   

    try{
    _RecordsetPtr m_pRs; CString bstrUpdateCSSQL;
    bstrUpdateCSSQL.Format("update ShoppingCart set shop_='1' where user_name='%s' and shop_='0'",strCookie);  
    m_pRs.CreateInstance(__uuidof(Recordset));
    m_pRs->CursorLocation = adUseClient;
    m_pRs->Open((LPCTSTR)bstrUpdateCSSQL, (LPCTSTR)m_strConnection,adOpenDynamic,adLockOptimistic, adCmdText); m_pRs->Close();
    m_pRs.Release();
    } catch (_com_error e)
    {
    _bstr_t m_bstrLastError; m_bstrLastError = e.Description(); *pCtxt << _T("<p>err:")<<m_bstrLastError;
    }
    ~~~~~~~~~能更新所有的记录,但是却catch出err:对象关闭时,不允许操作。