rs.Open strSql, cn, adOpenStatic, adLockBatchOptimistic
    
    Set rs.ActiveConnection = Nothing 'notice there is no cn now
    '下面这句运行完之后就把联接给关了,在此联接下的所有结果集也就被关了
    cn.Close        'u can close cn safely
    '下面这句就应该是时实错误了。
    Set rsOut = rs.Clone 'colne! a smart word :)
  

解决方案 »

  1.   

    Set rs.ActiveConnection = Nothing 这句也去掉。
      

  2.   

    我去掉了set rs.activeconnection=nothing 和cn.close 但还是取不到!麻烦小草在看看
    Public Function getRs(ByVal strSql As String, _
                            ByVal strConn As String, _
                            ByRef rsout As Recordset) As String
    On Error GoTo ErrTrap
        Dim cn As Connection
        Dim rs As Recordset
        Set cn = New Connection
        Set rs = New Recordset
        cn.ConnectionString = strConn
        cn.CursorLocation = adUseClient 'notice!
        cn.Open
        
        rs.Open strSql, cn, adOpenStatic, adLockBatchOptimistic
        
        Set rsout = rs.Clone 
        rs.Close
        
        Exit Function
        
    ErrTrap:
        If cn.State = adStateOpen Then _
            cn.Close
        If rs.State = adStateOpen Then _
            rs.Close
          
    End Function
      

  3.   

    搞什么?? Getrs也没有赋值呀
      

  4.   

    在Exit Function 之前  GetRs=...
      

  5.   

    你要得到哪个字段的值呀??
    getrs=rs.field("字段名")
    在赋值之前应该判断结果集是否为空
    if not(rs.bof and rs.eof ) then
        getrs=rs.field("字段名")
    endif
    exit function
      

  6.   

    小草同志,交个朋友,留下mail,或者oicq^_^
      

  7.   

    我按照if not(rs.bof and rs.eof ) then
        getrs=rs.field("字段名")
    endif试过,好像还是不行