不知道为什么,我在对数据库进行操作的时候,遇到了很奇怪的问题。
程序如下
    Dim CurRecordset As Recordset
    Dim CurDatabase As Database
    
    '打开数据库,建立连接
    Set CurDatabase = OpenDatabase(TempFilePath, False, False, "FoxPro 2.5;")
    
    '初始化Recordset
    Set CurRecordset = CurDatabase.OpenRecordset("Select * from " & FileName, dbOpenDynaset)
    
    CurRecordset.Close    Set CurRecordset = CurDatabase.OpenRecordset("Select * from " & FileName & " where Apptype = 'ping'", dbOpenDynaset)    在执行到第一个OpenRecordset的时候,返回的CurRecordset不为空,返回的是数据库中的所有的纪录。但执行第二个OpenRecordset查询的时候,返回的CurRecordset为Nothing。虽然按照这个SQL语句查询返回的结果集应该为0,但是CurRecordset不能为Nothing啊!到底我错在哪里?请给位老大给小弟一点儿指点!小弟感激不尽!
    还有,再VB中怎么判断一个变量为Nothing?

解决方案 »

  1.   

    if CurRecordset is nothing then
      

  2.   

    if CurRecordset is nothing then
      ...
    end if
      

  3.   

    if isnull(CurRecordset) then
    msgbox "NULL"
    else
    msgbox "NOT NULL"
    end if
      

  4.   

    isnull好像不好用,我试过了,is nothing好用。
    但是为什么Currecordset会为Nothing呢?
      

  5.   

    CurRecordset.Close
    去掉这句话在所有的操作完了之后再用
      

  6.   

    我看了看,发现如果查询结果为空就会设置CurRecordset为Nothing,不为空则不会为Nothing。
    困惑。
      

  7.   

    呵呵 Dim CurRecordset As new Recordset 大概就不會nothing了
      

  8.   

    Dim CurRecordset As new Recordset 
    我定义的时候都是这样,我不知道是为什么。你在重新连接的时候最好用一下,set currecordset=nothing.
      

  9.   

    set currecordset=nothing'释放对象