请问,recordset自己有没有什么属性或者方法可以得到记录条数?谢谢!

解决方案 »

  1.   

    dim rs as new adodb.recordset...MsbBox '当前记录数:' & rs.RecordCount
      

  2.   

    这样不行啊,我试过了。一直都等于-1,看MSDN说是如果采用的是TableRef的方式,该值就一直等于-1。没有别的方法吗?
      

  3.   

    应该是这样的, Jhzyz(Frank Feng黑名单上的人) 没有说错
    Dim Conn As New ADODB.Connection
    Conn.Open strCon
    Conn.CursorLocation = adUseClient
    Dim rs As New ADODB.Recordset
    rs.Open "select * from table", Conn, adOpenDynamic, adLockOptimistic
    msgbox(rs.count)
      

  4.   

    你先将记录移到最后一条,再使用recordcount
      

  5.   

    更正大家一个严重的错误,recordcount返回的并不是记录的条数。而是下面两种情况之一
    (1)最后一次记录指针移动的距离
    (2)-1
    最正确的做法是这样的。你们可以copy一下,当作模板来使用(开个玩笑了)
    dim i as long
    dim total as long
    dim adoRs as new adodb.recordset
    adors.open "select * from tablename where ....",adoCn
    if adors.bof or adors.eof then
        '没有符合条件的记录
    else
        adors.movelast
        adors.movefirst   '人为的让记录指针移动。移动距离等于记录条数。
        total=adors.recordcount
        if total = -1 then
            total=0
            do while not adors.eof
                 total=total+1
                 adors.movenext
            loop
            adors.movefirst
        endif
    endif
    for i= 1 to total
        '可以进行记录集的遍历了
    next i'最后两句话不要忘了,否则会造成内存泄漏。
    adors.close       
    set adors=nothing
      

  6.   

    将recordset.cursortype=adopenkeyset或adopenstatic时
    .recordcount返回的是记录数
      

  7.   

    楼上的都是不是太复杂哦!!!!   Dim rdcount As Integer      '记录个数
       Adodc1.ConnectionString = "dsn=ODBC库"
       Adodc1.CommandType = adCmdTable
       Adodc1.RecordSource = "表"
       Adodc1.Refresh
       rdcount = Adodc1.Recordset.recordcount
      

  8.   

    Dim rs As New ADODB.Recordset
    dim a as Integer      
    rs.Open "select  COUNT(*) AS aaa from table", Conn, adOpenDynamic, adLockOptimistic
    a=rs(aaa)
    rs.close
      

  9.   

    引用ADO3.6dim mdb as database,rst as recordset
    set mdb=opendatabase(数据库名)
    set rst=mdb.OpenRecordset("Select count(*) as aaa from 表名")
    msgbox "记录条数为:" & rst!aaa,,"OK"
    rst.close
    mdb.close这种方法返回的记录条数是准确的!
      

  10.   

    dim mydatabase as Database
    dim myrecordset as Recordset
    dim count as integer
    set mydatabase = workspace(0).opendatabase(".....")
    set myrecordset=mydatabase.openrecordset("表名,Type)
    myrecordset.movelast
    count=myrecoreset.recordcount
      

  11.   

    更正KEN的一个错误,-1代表没有记录,有记录时为1,你先执行一下MOVELAST方法,就可以用RECORDCOUNT得到正确的记录数了。