代码如下,程序运行的时候就出现消息框“删除记录出错!”,数据库里的记录也没有被删除,问题出在哪里啊?
void CTreeDataDlg::DeleteRecord(HTREEITEM hItem)
{ _RecordsetPtr m_pRecordset;
CString strSQL; TVITEM item;
TCHAR szText[1024];
item.hItem=hItem;
item.mask=TVIF_TEXT|TVIF_HANDLE;
item.pszText=szText;
item.cchTextMax=1024; m_ctrlTree.GetItem(&item); strSQL="DELETE * FROM treeitem where name=item.pszText "; try
{

    HRESULT hRes;
    hRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
    hRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
        _variant_t((IDispatch *)(((CTreeDataApp*)AfxGetApp())->m_pTreeConn),true),
    adOpenDynamic,adLockPessimistic,adCmdText);
}
catch(_com_error e)///捕捉异常
{
CString errormessage;
MessageBox("删除记录出错!");
}
}

解决方案 »

  1.   


    应该是那个SQL 语句错了吧, strSQL="DELETE * FROM treeitem where name=item.pszText ";
    其中item.psaText要加双引号什么的吧?正确的应该怎么写?
      

  2.   

    学JAVA和.net的同学让我改成:strSQL="DELETE * FROM treeitem where name='"+item.pszText+"'";
    编译错误:error C2110: cannot add two pointers还有下载的源码里有这样的句子,运行正确:
    strSQL="SELECT * FROM treeitem where rootname like '%" ;
    strSQL=strSQL+strFieldValue+"%'";上面两个句子的单引号和双引号是怎么用的?
      

  3.   

    strSQL.Format("DELETE * FROM treeitem where name='%s'",item.pszText);
      

  4.   

    strSQL.Format("DELETE * FROM treeitem where name='%s'",item.pszText);