读书人

SQL中怎么返回当前行

发布时间: 2012-01-22 22:38:43 作者: rapoo

SQL中如何返回当前行
我需要返回查询结果在记录集中所在位置,有一个笨办法,但是效率太低,有什么好的解决办法没

笨办法

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

如果记录多的话,速度就爆慢,有什么更好的办法没

[解决办法]
'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

读书人网 >VB

热点推荐