我用ADO连接了MYSQL
可是发现读出来的数据字段中,包含中文的都会少一般记录内容不知道大家有没有遇到过有什么好的解决方法没有读部分的代码如下 try{
pRecordset->Open(_variant_t("department"),
_variant_t((IDispatch *)pMyConnect,true), adOpenKeyset,
adLockOptimistic, adCmdTable);
try{
pRecordset->MoveFirst();
while(pRecordset->adoEOF==VARIANT_FALSE)
{
//Retrieve column's value: CString strDepartid=(char*)(_bstr_t)(pRecordset->Fields->GetItem
(_variant_t("departmentid"))->Value);
CString strDepartName=(char*)(_bstr_t)(pRecordset->Fields->GetItem
(_variant_t("departname"))->Value);
TRACE("%s---------------%s\n",strDepartid,strDepartName);
pRecordset->MoveNext();
}
pRecordset->Close();
}//try
catch (_com_error &e)
{
CString str=(char*)e.Description();
::MessageBox(NULL,str,"提示",MB_OK|MB_ICONWARNING);
} }
catch (_com_error &e)
{
::MessageBox(NULL,e.Description(),"提示",
MB_OK|MB_ICONWARNING);
}
可是发现读出来的数据字段中,包含中文的都会少一般记录内容不知道大家有没有遇到过有什么好的解决方法没有读部分的代码如下 try{
pRecordset->Open(_variant_t("department"),
_variant_t((IDispatch *)pMyConnect,true), adOpenKeyset,
adLockOptimistic, adCmdTable);
try{
pRecordset->MoveFirst();
while(pRecordset->adoEOF==VARIANT_FALSE)
{
//Retrieve column's value: CString strDepartid=(char*)(_bstr_t)(pRecordset->Fields->GetItem
(_variant_t("departmentid"))->Value);
CString strDepartName=(char*)(_bstr_t)(pRecordset->Fields->GetItem
(_variant_t("departname"))->Value);
TRACE("%s---------------%s\n",strDepartid,strDepartName);
pRecordset->MoveNext();
}
pRecordset->Close();
}//try
catch (_com_error &e)
{
CString str=(char*)e.Description();
::MessageBox(NULL,str,"提示",MB_OK|MB_ICONWARNING);
} }
catch (_com_error &e)
{
::MessageBox(NULL,e.Description(),"提示",
MB_OK|MB_ICONWARNING);
}
CString cSeqno;
_variant_t var;m_pRecordset.CreateInstance(__uuidof(Recordset));
try
{
m_pRecordset->Open("SELECT * FROM mytable",
m_pConnection.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}try
{
if(!m_pRecordset->BOF)
m_pRecordset->MoveFirst();
var = m_pRecordset->GetCollect("cmdsqeno");
if(var.vt != VT_NULL)
cSeqno = (LPCSTR)_bstr_t(var);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}m_pRecordset->Close();
m_pRecordset.Release();
m_pRecordset = NULL;