Private Sub Command1_Click()
    Dim Rectable As New ADODB.Recordset
    If Rectable.State = 1 Then Rectable.Close
    Rectable.CursorLocation = adUseClient
    
    
    Rectable.Open "Select * from passtable where 用户名='" & Text1.Text & "'", Conn, adOpenStatic, adLockBatchOptimistic
    If Rectable.RecordCount = 0 Then
        MsgBox "不存在此用户!", vbInformation, Me.Caption
        times = times + 1
        Exit Sub
    End If
    
    
    Rectable.Close
    Rectable.Open "Select * from passtable where 用户名='" & Text1.Text & "' and 密码='" & Text2.Text & "'", Conn, adOpenStatic, adLockBatchOptimistic
    If Rectable.RecordCount = 0 Then
        MsgBox "密码错误!", vbInformation, Me.Caption
        times = times + 1
        Exit Sub
    End If
    
    
    Rectable.Close
    Rectable.Open "Select * from passtable where 权限='admin'", Conn, adOpenStatic, adLockBatchOptimistic
    If Rectable.RecordCount = 0 Then
    
       ' If Rectable("权限") = "admin" Then
                       MsgBox "你无权进入"
        
    Else
    
       login.Visible = False
       main.Show
    
       ' End If
    End If
End Sub
这是我写的判断登陆的代码,  请检查权限那一段  进入之后 根本没有判断 无论 权限是否是"admin" 都能进入这是什么原因呢? 请高手帮我改正一下 思路!

解决方案 »

  1.   

    ' If Rectable("权限") = "admin" Then
                           MsgBox "你无权进入"          exit sub  '这要加个
            
        Else
        
           login.Visible = False
           main.Show
        
           ' End If
      

  2.   

    Rectable.Open "Select * from passtable where 用户名='" & Text1.Text & "'", Conn, adOpenStatic, adLockBatchOptimistic
        If Rectable.RecordCount = 0 Then
            MsgBox "不存在此用户!", vbInformation, Me.Caption
            times = times + 1
            Exit Sub
        End If
        
        
        If Rectable!密码 <> Text2.Text Then
            MsgBox "密码错误!", vbInformation, Me.Caption
            times = times + 1
            Exit Sub
        End If
         
        If Rectable!权限 <> "admin" Then               MsgBox "你无权进入"
        Else
        
           login.Visible = False
           main.Show
        
           ' End If
        End If因为你第3次查询是检索表中有无权限=Admin的记录,而不是当前用户是否Admin。
    另,也用不着多次查询。
      

  3.   

    Select * from passtable where 权限='admin' 
    这里有问题
    权限应该是和操作员表在一起的一个字段吧Select 权限 from passtable where 姓名=***"