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,对数据库不太明白,请大牛们帮忙

解决方案 »

  1.   

    把GetadoEOF()函数去掉更换为adoEOF试试。
      

  2.   

    while(!m_pRecordset->adoEOF)看看能不能行?理论上应该是可以了
      

  3.   

    VC有没有像C#内的那种SQLHelper类?
      

  4.   

    while(!pPtr->adoEOF)如果还是不行,你先看看pPtr是否为空?然后检查你的sql是否能执行.try catch 看看异常信息
      

  5.   

    你在stdafx.h中
    #import "c:\program files\common files\system\ado\msado15.dll" no_namespace rename("EOF","adoEOF")
    有没有 EOF 改为adoEOF
      

  6.   

    数据库open的时候出现异常了!~~我没有感觉连接字符串有问题啊!~~基本上就和.net也没有区别啊
      

  7.   

    检查你的链接串和SQL语句 
    最好能在数据库里测试一下 
      

  8.   

    把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);
    }
      

  9.   

    while(!m_pRecordset->adoEOF)
    把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);
    }
      

  10.   

    傳説要在vc中實現c#中的SQLHelper類是要自己封裝的
      

  11.   

    连接数据库异常,所以使用ptr就有问题       if(FAILED(pPtr->Open(varSRC,varSQL,adOpenStatic,adLockOptimistic,adCmdText)))
           {
              pPtr->Release();
              return;
           }
    连接失败以后返回就没有问题了
      

  12.   

    C#中的也是封装的啊!~
    难道VC中就没有封装好的类吗?
      

  13.   

    Provider=SQLOLEDB.1;Password=123456;Persist Security Info=True;User ID=sa;Data Source=192.168.0.70上面的是sqlserver的连接字符串,你可以根据情况修改