|
6金钱
本帖最后由 LeeTien 于 2012-3-31 08:04 编辑
写了一个ADO函数来获取Recordset对象
如下:
Public Function ADORs(ByVal data As String, ByVal Password As String, ByVal sql As String) As ADODB.Recordset
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
If con Is Nothing Then
Set con = New ADODB.Connection
Set rs = New ADODB.Recordset
End If
If Len(Password) = 0 Then
con.ConnectionString = "provider=Microsoft.Ace.OLEDB.12.0;Data Source=" & data & "ersist Security Info=False"
Else
con.ConnectionString = "provider=Microsoft.Ace.OLEDB.12.0;Data Source=" & data & ";Jet OLEDBatabase Password=" & masterDataPassword
End If
con.Open
rs.CursorLocation = adUseClient
sql = Trim(sql)
rs.Open sql, con, adOpenKeyset, adLockPessimistic
Set ADORs = rs
End Function
现在面临这样一个问题:要获取Recordset对象,不能在函数体内关闭Connection对象,也就是不能执行con.Close操作。这样会使程序一直占用连接,有什么办法在获取Recordset对象后关闭Connection对象吗。 |
|