问题1 (_bstr_t)pRst->GetCollect("client_project");返回乱码
sql1.Format("select * from ClientProject where client_id='%s'",(char*)(LPCTSTR)m_client_id.GetAt(i));//select * from ClientProject where client_id='001'
pRst=m_pConnection->Execute((_bstr_t)sql1,NULL,adCmdText);while(!pRst->adoEOF)
{
(_bstr_t)pRst->RecordCount;
tvInsert.hParent = main_sun1[i];
tvInsert.item.pszText =(char*)(LPCTSTR)(_bstr_t)pRst->GetCollect("client_project");
        //(char*)(LPCTSTR)(_bstr_t)pRst->GetCollect("client_project");添加到树中总是显示乱码
         //但用MessageBox((char*)(LPCTSTR)(_bstr_t)pRst->GetCollect("client_project"));就OK
tvInsert.item.iImage=2;
tvInsert.item.iSelectedImage=5;
HTREEITEM main_sun1_1=GetTreeCtrl().InsertItem(&tvInsert);
pRst->MoveNext();
}
问题2
如何通过记录集获得表内数据数
sql1.Format("select * from ClientProject where client_id='%s'",(char*)(LPCTSTR)m_client_id.GetAt(i));//select * from ClientProject where client_id='001'
pRst=m_pConnection->Execute((_bstr_t)sql1,NULL,adCmdText);
如何通过pRst获得表内数据数量,试过int k=pRst->RecordCount;没用

解决方案 »

  1.   

    给你一点参考代码: _RecordsetPtr pPtr; if (FAILED(pPtr.CreateInstance("ADODB.Recordset")))
    {
    AfxMessageBox("Create Instance failed!");
    return;
    } CString strSRC = GetConnSrc(strPath, strFn);
    CString strSQL; strSQL = "select * from ClientProject order by client_id asc"; try
    {
    if(FAILED(pPtr->Open(_bstr_t(strSQL), _bstr_t(strSRC), adOpenStatic, adLockOptimistic, adCmdText)))
    {
    AfxMessageBox("Open table failed!");
    pPtr.Release();
    return;
    }
    }
    catch(...)
    {
    AfxMessageBox("打开数据库出错!");
    pPtr->Close();
    }
    HTREEITEM hRoot = m_wndTree.GetRootItem();
    while(!pPtr->GetadoEOF())
    {
    _variant_t varId = pPtr->GetCollect("client_id");
    CString strId = (char *)_bstr_t(varId); _variant_t varname = pPtr->GetCollect("name");
    CString strname = (char *)_bstr_t(varname); HTREEITEM hItem = m_wndTree.InsertItem(_T(strname), 9, 9, hRoot);
    pPtr->MoveNext();
    }
    pPtr->Close();
    pPtr.Release();
      

  2.   

    1、_variant_t var;var = pRst->GetCollect("client_project");
    tvInsert.item.pszText =(char*)(LPCTSTR)(_bstr_t)var;2\http://blog.csdn.net/zaodt/archive/2008/04/15/2295164.aspx
      

  3.   

    非常感谢楼上的帮忙第一个问题还是没解决返回的还是乱码,但用MESSAGEBOX看就没问题第二个问题已经解决非常感谢!!!不知道第一个问题到底问题出在哪!!
      

  4.   

    第一个问题,不用MessageBox输出,直接在调试窗口看到的值是什么?
      

  5.   

    如果     tvInsert.item.pszText =(char*)(LPCTSTR)(_bstr_t)var;
    单步调试到HTREEITEM main_sun1_1=GetTreeCtrl().InsertItem(&tvInsert);就出现栈溢出
    但如果
             tvInsert.item.pszText ="11111";
            HTREEITEM main_sun1_1=GetTreeCtrl().InsertItem(&tvInsert);就正常
      

  6.   

    搞不懂了郁闷~吧var转成CString在赋给tvInsert.item.pszText 就没问题~~