void WINAPI CEChinaJobColDlg::StartCollectThread(string* url)
{
::CoInitialize(NULL);
_RecordsetPtr pPtr;
if(FAILED(pPtr.CreateInstance(__uuidof(Recordset))))
{
return;
}
//pPtr.CreateInstance(__uuidof(Recordset));
CString connstr("Driver=SQL Server;Server=192.168.0.6;Database=EChinaJob;UID=sa;PWD=sa");
CString strSQL("select top 20 PersonID,RealName from ecj_Person");
_variant_t varSRC(connstr);
_variant_t varSQL(strSQL);
try
{
if(FAILED(pPtr->Open(varSRC,varSQL,adOpenStatic,adLockOptimistic,adCmdText)))
{
pPtr->Release();
}
}
catch(_com_error &e)
{} while(!pPtr->GetadoEOF()) //运行到此处的时候,出现错误!请问为什么
{
_variant_t varID;
_variant_t varName; varID = pPtr->GetCollect("PersonID");
varID = pPtr->GetCollect("RealName");
}
//string u = *url;
}
才开始学VC,对数据库不太明白,请大牛们帮忙
#import "c:\program files\common files\system\ado\msado15.dll" no_namespace rename("EOF","adoEOF")
有没有 EOF 改为adoEOF
最好能在数据库里测试一下
{
printf("Error\n");
printf("\a\tCode = %08lx\n", e.Error());
printf("\a\tCode meaning = %s", e.ErrorMessage());
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
printf("\a\tSource = %s\n", (LPCSTR) bstrSource);
printf("\a\tDescription = %s\n", (LPCSTR) bstrDescription);
}
把while循环也放到try块中 完善catch功能块,然后看出了什么错误void dump_com_error(_com_error &e)
{
printf("Error\n");
printf("\a\tCode = %08lx\n", e.Error());
printf("\a\tCode meaning = %s", e.ErrorMessage());
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
printf("\a\tSource = %s\n", (LPCSTR) bstrSource);
printf("\a\tDescription = %s\n", (LPCSTR) bstrDescription);
}
{
pPtr->Release();
return;
}
连接失败以后返回就没有问题了
难道VC中就没有封装好的类吗?