首页 文章

当没有下一个记录集时,ASP ADO recordset.NextRecordset()会中断

提问于
浏览
0

我已经完成了try / catch块以及我能想到的每个测试,但是代码只是中断并且给出了内部服务器错误 . 我希望有一个我错过的 isNextRecordset()isLastRecordset() 功能 .

我目前的守则

do{
    //Some Code Stuff

    record = record.NextRecordset();  //Dies here when no more recordsets

}while(!!record);

使用普通的VBScript,他们会显示此方法有效(但从未尝试过) . 但我不想使用VBScript .

VBScript代码

Do Until record = Nothing

   set record = record.NextRecordset
Loop

编辑:我相信我通过添加循环使事情变得混乱,如果你删除循环并只是在没有下一个记录集时调用nextrecordset一次它仍然死亡 . 无需测试null . 我的代码没有进行null测试 .

//Get A recordset
//There is only one recordset
record = cmd.Execute();

//Do some stuff with the record set

//Call NextRecordset
//even though there are no more
record = record.NextRecordset();  //<--- Still Dies right here

编辑:只是想指出我遇到的隐藏问题 . 下面的答案是正确的,但不是我的实际问题 . 我看到的一些教程显示了如下结构 . 关闭记录和连接 . 但到 record 到底时它已经 null ,这是一个问题 . 这很容易通过显示正确的错误消息来解决,这是我没有的 . 我自己的愚蠢,但可能会帮助别人 .

try{

   //Do Some Stuff

   record = record.NextRecordset();

   //Test Record set  

}catch(e){

}finally{
    record.Close();  <---- This is where it was actually having a problem. 
    record = null;
    myconn.Close();
    myconn = null;
}

1 回答

  • 1

    适当的语法是:

    while (record) {
        //Some Code Stuff
    
        record = record.NextRecordset();
    }
    

    这样,当 NextRecordset() 将返回null时,循环将停止 .

相关问题