VB程序员博客
我需要返回查询结果在记录集中所在位置,有一个笨办法,但是效率太低,有什么好的解决办法没
笨办法
dim curnum as integer
rs.open "select * from data_info ",conn,1,3
if rs.recordcount <> 0 then
do while not rs.eof
curnum=curnum+1
if rs( "ID ")= "DT070501137 " then
exit do
end if
loop
end if
rs.close
如果记录多的话,速度就爆慢,有什么更好的办法没
WHERE
或者在 Recordset 使用 SEEK()/FIND() 函数
请参考 MSDN
不行啊,老兄
select * from data_info where ID= 'DT070501137 '
数据库允许的话在加个自增字段吧,那就可以根据Select count(自增字段) from 表 where 自增字段 <(select 自增字段 from 表 where ID= 'DT070501137 ')了
TO CathySun118(斯年)
你可能理解错误题目了,我不是要查询,只是要返回这条记录在整个数据集中的第几行
TO danielinbiti(金)
表中是有一个字段为自增字段,但是这个字段并不能代表所在记录行,中间可能有数据被删除的,所以并不连贯
ado的AbsolutePosition属性。
'Try it!
Sub ADOFindRecord()
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
' Open the connection
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=.NorthWind.mdb; " 'Your Source Database path
' Open the recordset
rst.Open "Customers ", cnn, adOpenKeyset, adLockOptimistic
' Print the absolute position
Debug.Print "rst.AbsolutePosition_1= ";rst.AbsolutePosition
' Find the first customer whose country is USA
rst.Find "ID= 'DT070501137 ' "
Debug.Print "rst.AbsolutePosition_2= ";rst.AbsolutePosition
' Print the customer id 's of all customers in the USA
Do Until rst.EOF
rst.Find "ID= 'DT070501137 ' ",1
Debug.Print "rst.AbsolutePosition_3= ";rst.AbsolutePosition
Loop
' Close the recordset
rst.Close
End sub
标签: 返回