1,217
社区成员




' conn 为全局的数据连接对象
Dim str_sql As String, _
i As Long, _
rs As Recordset, _
rs_count As Long
Set rs = New Recordset
' 这里是根据条件统计数据数量
str_sql = "select count(id) as c from 表1 where ff link '%ABC%'"
rs.open str_sql,conn,3,1
rs_count = rs!c
rs.close
if rs_count>0 then
' 这里是用相同的条件同时排序查询具体的数据
str_sql = "select * from 表1 where ff link '%ABC%' order by id"
rs.open str_sql,conn,3,1
for i=1 to rs_count
debug.print rs!id
if i<rs_count then rs.movenext
next i
rs.close
end if
Set rs = Nothing
这样的操作特别是对于数据量大的时候速度差别最为明显。
所以我之前才说你的数据库操作习惯很不正确。