我编写了一个基本的 asp 经典类来处理与我们数据库的所有连接。第一次调用时一切正常,但第二次调用记录集时没有打开任何想法?
Class SQLConnection
Private Sub Class_Initialize
set ConnectionObject = Server.CreateObject("ADODB.Connection")
Set RecordsetObject = Server.CreateObject("ADODB.Recordset")
End Sub
Private Sub Class_Terminate
Set ConnectionObject = Nothing
Set RecordsetObject = Nothing
End Sub
Public Default Property Get Item(sString)
On Error Resume Next
Item = RecordsetObject(sString)
On Error GoTo 0
If Err.Number <> 0 then
Item = null
End if
End Property
Public Sub MoveNext
If Not RecordsetObject.EOF Then RecordsetObject.MoveNext
End Sub
Public Function EOF
EOF = RecordsetObject.EOF
End Function
Public Sub Open(SQLStr,ConnStr)
ConnectionObject.Open ConnStr
RecordsetObject.Open SQLStr, ConnectionObject, 3
End Sub
Public Sub Close
RecordsetObject.Close
ConnectionObject.Close
End Sub
End Class
Set SQLConn = New SQLConnection
SQLConn.Open "SELECT top 10 id FROM tblProfileVillages", ConnectionString
Do While Not SQLConn.EOF
Response.write(SQLConn("id"))
SQLConn.MoveNext
Loop
SQLConn.Close
Set SQLConn = nothing