justinfly
justinfly

Reputation: 179

VC 6.0 MFC How to read unicode data from sql server into CListBox

I have created a VC6.0 MFC app. I also set the project in unicode mode. enter image description hereenter image description here

But I when I load the unicode data (e.g. Russian) from sql db, I also get question mark string "????..."

_variant_t TheValue;

CString str;
try
{
    m_list.ResetContent();
    //m_pConnection.CreateInstance(_uuidof(Connection));
    m_pRecordset.CreateInstance(_uuidof(Recordset));

    m_pRecordset->Open("SELECT * FROM MyUser",(IDispatch*)m_pConnection, adOpenDynamic, adLockOptimistic,adCmdText);

    while(!m_pRecordset->adoEOF)
    {
        TheValue = m_pRecordset->GetCollect("name");
        if(TheValue.vt!=VT_NULL)
        {
            str=(LPCSTR)_bstr_t(TheValue);
            m_list.AddString(str);

        }

        m_pRecordset->MoveNext();       
    }
    m_pRecordset->Close();
}
catch(_com_error e)
{
    CString errormessage;
    errormessage.Format(L"Connect failedr\n error:%s", e.ErrorMessage());
    AfxMessageBox(errormessage);
}

Upvotes: 2

Views: 176

Answers (0)

Related Questions