应该是这样的, 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)
你先将记录移到最后一条,再使用recordcount
更正大家一个严重的错误,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
楼上的都是不是太复杂哦!!!! Dim rdcount As Integer '记录个数 Adodc1.ConnectionString = "dsn=ODBC库" Adodc1.CommandType = adCmdTable Adodc1.RecordSource = "表" Adodc1.Refresh rdcount = Adodc1.Recordset.recordcount
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
引用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这种方法返回的记录条数是准确的!
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
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)
(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
.recordcount返回的是记录数
Adodc1.ConnectionString = "dsn=ODBC库"
Adodc1.CommandType = adCmdTable
Adodc1.RecordSource = "表"
Adodc1.Refresh
rdcount = Adodc1.Recordset.recordcount
dim a as Integer
rs.Open "select COUNT(*) AS aaa from table", Conn, adOpenDynamic, adLockOptimistic
a=rs(aaa)
rs.close
set mdb=opendatabase(数据库名)
set rst=mdb.OpenRecordset("Select count(*) as aaa from 表名")
msgbox "记录条数为:" & rst!aaa,,"OK"
rst.close
mdb.close这种方法返回的记录条数是准确的!
dim myrecordset as Recordset
dim count as integer
set mydatabase = workspace(0).opendatabase(".....")
set myrecordset=mydatabase.openrecordset("表名,Type)
myrecordset.movelast
count=myrecoreset.recordcount