有个ADO程序。自我感觉没啥问题,可是运行就是没反应,还请大家帮忙看看_ConnectionPtr m_pConnection;
_RecordsetPtr m_pRecordset;
_CommandPtr m_pCommand;
m_pConnection.CreateInstance(__uuidof(Connection));
m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Data//Tally.mdb","","",adModeUnknown);
m_pCommand.CreateInstance(__uuidof(Command));
m_pCommand->ActiveConnection = m_pConnection; /* 将库连接赋于它 */
m_pCommand->CommandText = "SELECT * FROM TallyUser"; /* SQL语句 */
m_pCommand->CommandType=adCmdText; 
m_pCommand->Parameters->Refresh(); 
m_pRecordset = m_pCommand->Execute(NULL, NULL, adCmdUnknown); /* 执行SQL语句,返回记录集 */运行的结果m_pRecordset->RecordCount==-1,但是数据库里是有数据的

解决方案 »

  1.   

    一般不用这个RecordCount进行任何的判断。
      

  2.   

    con.Execute参数详解
    参数
    CommandText    字符串,包含要执行的 SQL 语句、表名、存储过程或特定提供者的文本。
    RecordsAffected    可选,长整型变量,提供者向其返回操作所影响的记录数目。http://www.cnblogs.com/aoyihuashao/archive/2009/12/22/1629650.html
      

  3.   

    COMMAND的exec用法应该也一样的
      

  4.   

    m_pRecordset->RecordCount==-1;
    //要想使这个起作用,起码要加上 
    m_pRecordset->CursorLocation=adUseClient; //使用客户端游标,ADO默认是服务器端游标。//很少用这个判断数据集是否有值
    if(m_pRecordset->EOF && m_pRecordset->BOF) //记录集指针同时为记录头和记录尾,则没有数据。
      

  5.   

    直接sql查询好了,select count from ...
      

  6.   


    呵呵,我以前就是这么判断的,不过不用BOF,查询后就是BOF,直接if(m_pRecordset->EOF)
      

  7.   

    是不是ACCESS数据库路径有问题?
    哦MSSQL的没问题,没搞过,学习try
    {
    CoInitialize(NULL);
    _ConnectionPtr pConn(__uuidof(Connection));
    _RecordsetPtr pRst(__uuidof(Recordset));
    /*pConn->ConnectionString="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;PassWord=123;Server=.;Initial Catalog=WirelessCare";*/
    pConn->ConnectionString=((_bstr_t)ConfigConnString);
    pConn->Open("","","",adConnectUnspecified);
    pRst=pConn->Execute("select * from City",NULL,adCmdText);
    while(!pRst->rsEOF)
    {
    int iPos=m_MyList->InsertItem(0,(_bstr_t)pRst->GetCollect("id"));
    m_MyList->SetItemText(iPos,1,(_bstr_t)pRst->GetCollect("name"));
    m_MyList->SetItemText(iPos,2,(_bstr_t)pRst->GetCollect("provinceid")); pRst->MoveNext();
    }
    pRst->Close();
    pConn->Close();
    pRst.Release();
    pConn.Release();
    CoUninitialize();
    }
    catch(_com_error e)
    {
      AfxMessageBox(e.Description()); 
    }希望对您有用
      

  8.   

    如果不使用m_pRecordset->RecordCount,那在进行数据个数统计的时候岂不是要再写SQL判断个数?
      

  9.   

    加了这句m_pRecordset->CursorLocation=adUseClient
    程序就挂在这句了
      

  10.   


    // 在_ConnectPtr->Open()之前加
      

  11.   


    在_ConnectPtr->Open()之前加 还是挂了
      

  12.   


    // 贴下代码看看?还有ADO版本,数据库版本,VC版本。
      

  13.   


    _ConnectionPtr    m_pConnection;    
    _RecordsetPtr    m_pRecordset;    
    _CommandPtr    m_pCommand;
    if (!AfxOleInit()) 

    AfxMessageBox("OLE初始化出错!"); 

    m_pConnection.CreateInstance(__uuidof(Connection));   
    m_pRecordset->CursorLocation = adUseClient; 
    m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Data//Tally.mdb","","",adModeUnknown);
    m_pCommand.CreateInstance(__uuidof(Command));
    m_pCommand->ActiveConnection = m_pConnection;                /* 将库连接赋于它 */
    m_pCommand->CommandText = "SELECT * FROM TallyUser";        /* SQL语句 */
    m_pCommand->CommandType=adCmdText; 
    m_pCommand->Parameters->Refresh(); 
    m_pRecordset = m_pCommand->Execute(NULL, NULL, adCmdUnknown);    /* 执行SQL语句,返回记录集 */一个函数就这样而已,到m_pRecordset->CursorLocation = adUseClient; 这一句就挂了
    ADO不知道啥版本,引用的是msado15.dll
    数据库使用acess 2003格式
    vc是6.0 sp6
      

  14.   

    _RecordsetPtr m_pRecordset;
    m_pRecordset.CreateInstance(__uuidof(Recordset));   
    m_pRecordset->CursorLocation = adUseClient; 
      

  15.   

    // 经常用SELECT COUNT(*) AS rsCount FROM table
    // 然后取rsCount的值来判断记录数。
    // 客户端游标在大数据量时效率不如服务端游标。