各位大虾请问:为什么我用get_RecordCount()函数不能获取记录数(用RecordCount()也不行)!返回值总是-1,在线等!

解决方案 »

  1.   

    你需要先从头到尾遍历这个这个数据表后,才能用这个函数得到记录数的正确值,
    可以在调用这个函数以前,先执行一下这个SQL语句:select * from 数据表名试一试,祝你好运!!!
      

  2.   

    谢谢,我用的是Open(select * from 数据表,....)打开数据库表的
      

  3.   

    打开方式的错误
    就是什么动态,快照之类的
    查下书吧
    以前我作asp的时候也遇到过
      

  4.   

    get_RecordCount()
    应该先判定,在遍历,然后调用的
      

  5.   

    ///这是msdn的example,但是实际取不到,不知道为什么!在后面提供了一个解决办法,参考
    strCnn = "Provider=sqloledb;" & _
          "Data Source=srv;Initial Catalog=pubs;User Id=sa;Password=; "
       Set rstPublishers = New ADODB.Recordset
       rstPublishers.CursorType = adOpenStatic
       rstPublishers.Open "publishers", strCnn, , , adCmdTable   ' 充填记录集。
       intPublisherCount = rstPublishers.RecordCount
    /////////////////////////////////////////////////////////
    select count(*) from tablename;
    返回值就是记录数!
      

  6.   

    设置静态游标就行
    CursorType = adOpenStatic
      

  7.   

    只要遍历过后再调用GETRECORDCOUNT就可以了
    我今天也见到过,遍历后不要记数都可以得到记录个数
      

  8.   

    第三个参数只有当为adOpenKeyset和adOpenStatic,第四个参数不填或填adLockReadOnly时,recordcount才能返回正确的数.
      

  9.   

    感谢大家对这个问题的关注我的源代码如下:
    m_arearecord.CreateInstance(__uuidof(Recordset));
    m_arearecord->Open("select * from area", theApp.m_mycnn.GetInterfacePtr(), adOpenDynamic,adLockOptimistic, adCmdText);
    //获取记录总条数
    m_arearecord->get_RecordCount(&intArea);//用该语句无法获得总条数感谢DebugXP,用静态游标可以解决该问题!谢谢大学的关注!