Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp classic 无法打开记录集_Asp Classic - Fatal编程技术网

Asp classic 无法打开记录集

Asp classic 无法打开记录集,asp-classic,Asp Classic,我已经编写了一个基本的asp经典类,它处理到数据库的所有连接。 第一次调用时,一切正常,但第二次调用时,记录集没有打开任何想法 Class SQLConnection Private Sub Class_Initialize set ConnectionObject = Server.CreateObject("ADODB.Connection") Set RecordsetObject = Server.CreateObject("ADODB.Recordset") End S

我已经编写了一个基本的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
类SQLConnection
私有子类_初始化
设置ConnectionObject=Server.CreateObject(“ADODB.Connection”)
Set RecordsetObject=Server.CreateObject(“ADODB.Recordset”)
端接头
私有子类
设置ConnectionObject=Nothing
Set RecordsetObject=Nothing
端接头
公共默认属性获取项(sString)
出错时继续下一步
Item=RecordsetObject(sString)
错误转到0
如果错误号为0,则
Item=null
如果结束
端属性
公共分拆
如果不是RecordsetObject.EOF,则为RecordsetObject.MoveNext
端接头
公共功能
EOF=RecordsetObject.EOF
端函数
公共子打开(SQLStr、ConnStr)
ConnectionObject.openconnstr
RecordsetObject.Open SQLStr,ConnectionObject,3
端接头
公开分拆
RecordsetObject.Close
连接对象。关闭
端接头
末级
设置SQLConn=newsqlconnection
打开“从tblProfileVillages中选择前10个id”,连接字符串
不要使用SQLConn.EOF,而不要使用SQLConn.EOF
write(SQLConn(“id”))
SQLConn.MoveNext
环
SQLConn.Close
设置SQLConn=nothing

我认为错误在
属性中,您必须先检查
错误号
,然后在错误转到0时调用

像这样使用它:

Public Default Property Get Item(sString)
    On Error Resume Next
    Item = RecordsetObject(sString)
    If Err.Number  <> 0 then
        Item = null
    End if
    On Error GoTo 0
End Property
公共默认属性获取项(sString)
出错时继续下一步
Item=RecordsetObject(sString)
如果错误号为0,则
Item=null
如果结束
错误转到0
端属性
我还没有在vbScript中看到“null”。这是你做的一个常数,还是你遗漏了一个错误?
错误转到下一步时的
业务有时会很烦人。:)

结果是,如果sql语句不能显示在网格中,那么对象会像insert语句一样立即关闭


我通过在运行带有
if RecordsetObject.State=1的代码之前检查对象是否打开来解决这个问题,然后
Null
是VBScriptThank可以识别的关键字。谢谢,但这并没有修复错误
错误转到下一个
是必需的,因为
记录集
在解析列名时会抛出错误它不存在,
isObject
和其他类似的内置函数无法处理
记录集
object@AnonJr:有趣的是,我从不需要
null
在使用VbScript的这些年里,我使用了vbNull@托马斯:这很清楚,但有时我会在我没有预料到的地方掩盖“变量未定义”错误。@gpinkas-我自己通常使用vbNull或空字符串(“”),但我知道它存在。没有什么比得到相同结果的多种方法更有效的了。。。