下面给出代码,也没有抛出异常,列表框里删掉了,但在数据库里面没有删掉,如果我改过m_pConnection->Execute("delete from beiwang where users='QQ'",&RecordsAffected,adCmdText);是能删掉用户名为QQ的数据库记录的。我调试过Guser和sevent两个变量都是对的。但就是删除操作没有反应,只删除了列表框里的数据。
void CDelbeiwang::Ondelbeiwang() 
{
// _variant_t vuser,vevents;
HWND hWnd = ::GetDlgItem(m_hWnd, IDC_LIST1);
CListCtrl * m_List=((CListCtrl * )GetDlgItem(IDC_LIST1));
int nitem=m_List->GetSelectionMark();
CString sevent=GetItemText(hWnd,nitem,1);
try
{
m_pConnection->Execute("delete from beiwang where users='+Guser+' and events='+sevent+'",&RecordsAffected,adCmdText);
}
catch(_com_error e)
{
AfxMessageBox(e.ErrorMessage(),MB_OK,0);
}
m_list.DeleteItem(m_List->GetSelectionMark());
UpdateData(FALSE);
// TODO: Add your control notification handler code here

}

解决方案 »

  1.   

    _CommandPtr m_pCommand; m_pCommand.CreateInstance(__uuidof(Command));
    m_pCommand->ActiveConnection = theApp.m_pConnection;  // 将库连接赋于它
    m_pCommand->CommandText = _bstr_t((LPCTSTR)m_strCommand);  // SQL语句
    try 
    {
    // 执行SQL语句,返回记录集,此记录不能做插入操作
    // 故为了不和m_pRecordset相冲突, 放入新定义的m_pRecordset1
    m_pRecordset1 = m_pCommand->Execute( NULL, NULL, adCmdText); 
    }
    catch(_com_error& e)
    {
    dump_com_error(e);
    }
      

  2.   

    http://blog.csdn.net/zyq5945/archive/2010/04/29/5541280.aspx
      

  3.   

    在打开记录集之前调用UpdateData();试试看