返回Recordset后,与数据库断开连接(ADODB)
Private Sub Command1_Click()
Dim szSQL As String
Dim conn As New ADODB.Connection
Dim rs As ADODB.Recordset
conn.ConnectionString = m_conStr
conn.CursorLocation = adUseClient
conn.Open
szSQL = "select * from table1"
Set rs = conn.Execute(szSQL)
rs.ActiveConnection = Nothing '如果是服务器短光标,则此句会出错,就不能脱离连接
conn.Close
Set conn = Nothing
While Not rs.EOF
Debug.Print "[" & Now & "]" & rs.Fields(0) & ":" & rs.Fields(1)
rs.MoveNext
Wend
End Sub
Dim szSQL As String
Dim conn As New ADODB.Connection
Dim rs As ADODB.Recordset
conn.ConnectionString = m_conStr
conn.CursorLocation = adUseClient
conn.Open
szSQL = "select * from table1"
Set rs = conn.Execute(szSQL)
rs.ActiveConnection = Nothing '如果是服务器短光标,则此句会出错,就不能脱离连接
conn.Close
Set conn = Nothing
While Not rs.EOF
Debug.Print "[" & Now & "]" & rs.Fields(0) & ":" & rs.Fields(1)
rs.MoveNext
Wend
End Sub