把数据库的连接写到一个公共模块,dbconn.open"......"
不知道修改住那个地方了现在出现----对象打开时不允许操作
    
        '按值进行搜索
        Dim strsql As String
        strsql = "select * from 合同表 where " & Trim(cobSerch.Text) & "='" & Trim(txtSerchz.Text) & "'"
        dbRecord.CursorLocation = adUseClient  --------------错误句  对象打开时不允许操作
        dbRecord.Open strsql, dbConn, adOpenStatic, adLockOptimistic
        Set Me.mgrdShowH.DataSource = dbRecord
               
问题出在那了,谁给分析下。是不是要在代码的最后加一句dbrecord.close,在没出问题以前我第一次点击搜索时结果正常,在点时也会出现->对象打开时不允许操作,是不是要关闭记录?会不会影响到别的dbrecord?

解决方案 »

  1.   

    之前加入
    if dbRecord.State<>0 then dbRecord.close
      

  2.   

    With ADOTemp
        If .State <> adStateOpen Then
            .ActiveConnection = ADOsdb
            .CursorLocation = adUseClient
            .CursorType = adOpenStatic
            .LockType = adLockBatchOptimistic
            .Open "SELECT * From db order by 序号", Options:=adCmdText
            Set .ActiveConnection = Nothing
        Else
            Set .ActiveConnection = Nothing
        End If
        
    End With
      

  3.   

    Dim strsql As String 
    strsql = "select * from 合同表 where " & Trim(cobSerch.Text) & "='" & Trim(txtSerchz.Text) & "'" 
    If dbRecord.State  <> adStateClosed Then
       dbRecord.close
    endif
    dbRecord.CursorLocation = adUseClient 
    dbRecord.Open strsql, dbConn, adOpenStatic, adLockOptimistic 
    Set Me.mgrdShowH.DataSource = dbRecord