程序基本内容是这样的,启动时连接一个 access 数据库,里面有一个 login 的表,表中存有 id 和 password 两个字段,
    
    想设置一个登录窗口,用户名取表 id 列的内容, 选择用户名后,与表中 password 中的密码进行匹配,成功能进入下个菜单,请问用 ADO 代码如何实现?

解决方案 »

  1.   

       我采用的是输入用户名和密码
     Dim msg  As String
        Set snp = Nothing
        s = " SELECT  授权.*"
        s = s & " FROM 授权 "
        s = s & " where 授权.编号='" & Trim$(nametxt.Text) + "'    
        snp.Open s, cn
        If snp.EOF Then
            Chk = 1
        Else
            If Not IsNull(snp("口令")) Then
                If txtpwd.Text <> snp("口令") Then
                    Chk = 2
                End If
            Else
                If txtpwd.Text <> "" Then
                    Chk = 2
                End If
            End If
        End If
        If Chk = 0 Then
            DoEvents
            '下边为进入程序    Else
            counter = counter - 1
            If counter = 0 Then
                msg = Chr$(13) & "你不是合法用户!" & Chr$(13) & "对不起,再见!"
                MsgBox msg, 48
                cn.Close
                Set snp = Nothing
                Set cn = Nothing
                End
            ElseIf counter = 1 Then
                msg = Chr$(13) & "这是最后一次.请仔细!"
            Else
                msg = Chr$(13) & "别急,想好.请再试一次"
            End If
            If Chk = 1 Then
                MsgBox "无此编号∶" & nametxt.Text & msg, 48
            ElseIf Chk = 2 Then
                MsgBox "错误口令" & Chr$(13) & msg, 48
            End If
            txtpwd.Text = ""
        End If
      

  2.   

       '参考以下这段:
        If Trim(txtcUserName.Text) = "" Then
            MsgBox "请输入登录用户!", 48, "提示"
            Screen.MousePointer = vbDefault
            txtcUserName.SetFocus
            Exit Sub
        End If
        
        StrSql = " select cUserCode,cUserName,cUserpwd,bUserAdmin,bUserFbd from users " _
               & " where cUserCode='" & Trim(txtcUserName.Text) & "'"
        If ar_Tmp.State <> adStateClosed Then ar_Tmp.Close
        ar_Tmp.Open StrSql, g_strConn, adOpenKeyset, adLockReadOnly
        If ar_Tmp.RecordCount = 0 Then
            MsgBox "登录用户或密码错误!", 48, "提示"
            Screen.MousePointer = vbDefault
            ar_Tmp.Close
            Exit Sub
        Else
            If Not (IsNull(ar_Tmp!cUserPwd) Or ar_Tmp!cUserPwd = "") Then
                If Trim(ar_Tmp!cUserPwd) <> Trim(txtcPassword.Text) Then
                    MsgBox "登录用户或密码错误!", 48, "提示"
                    If ar_Tmp.State <> adStateClosed Then ar_Tmp.Close
                    Screen.MousePointer = vbDefault
                    Exit Sub
                End If
            Else
                If Trim(txtcPassword.Text) <> "" Then
                    MsgBox "登录用户或密码错误!", 48, "提示"
                    If ar_Tmp.State <> adStateClosed Then ar_Tmp.Close
                    Screen.MousePointer = vbDefault
                    Exit Sub
                End If
            End If
            
            g_strUserCode = ar_Tmp!cUserCode
            g_strUserName = ar_Tmp!cUserName
            '是否系统管理员
            If ar_Tmp!bUserAdmin = True Then
                g_blnUserAdmin = True
            Else
                g_blnUserAdmin = False
            End If
        End If
        If ar_Tmp.State <> adStateClosed Then ar_Tmp.Close
      

  3.   

        '参考以下这段:
        If Trim(txtcUserName.Text) = "" Then
            MsgBox "请输入登录用户!", 48, "提示"
            Screen.MousePointer = vbDefault
            txtcUserName.SetFocus
            Exit Sub
        End If
        
        StrSql = " select cUserCode,cUserName,cUserpwd,bUserAdmin,bUserFbd from nbuf_users " _
               & " where cUserCode='" & Trim(txtcUserName.Text) & "'"
        If ar_Tmp.State <> adStateClosed Then ar_Tmp.Close
        ar_Tmp.Open StrSql, g_strConn, adOpenKeyset, adLockReadOnly
        If ar_Tmp.RecordCount = 0 Then
            MsgBox "登录用户或密码错误!", 48, "提示"
            Screen.MousePointer = vbDefault
            ar_Tmp.Close
            Exit Sub
        Else
            If Not (IsNull(ar_Tmp!cUserPwd) Or ar_Tmp!cUserPwd = "") Then
                If Trim(ar_Tmp!cUserPwd) <> Trim(txtcPassword.Text) Then
                    MsgBox "登录用户或密码错误!", 48, "提示"
                    If ar_Tmp.State <> adStateClosed Then ar_Tmp.Close
                    Screen.MousePointer = vbDefault
                    Exit Sub
                End If
            Else
                If Trim(txtcPassword.Text) <> "" Then
                    MsgBox "登录用户或密码错误!", 48, "提示"
                    If ar_Tmp.State <> adStateClosed Then ar_Tmp.Close
                    Screen.MousePointer = vbDefault
                    Exit Sub
                End If
            End If
            
            g_strUserCode = ar_Tmp!cUserCode
            g_strUserName = ar_Tmp!cUserName
            '是否系统管理员
            If ar_Tmp!bUserAdmin = True Then
                g_blnUserAdmin = True
            Else
                g_blnUserAdmin = False
            End If
        End If
        If ar_Tmp.State <> adStateClosed Then ar_Tmp.Close
      

  4.   

    If Trim(txtcUserName.Text) = "" Then
        MsgBox "请输入登录用户!", 48, "提示"
        Screen.MousePointer = vbDefault
        txtcUserName.SetFocus
        Exit Sub
    End If
       
    StrSql = " select cUserCode,cUserName,cUserpwd,bUserAdmin,bUserFbd from nbuf_users " _
           & " where cUserCode='" & Trim(txtcUserName.Text) & "'"
    If ar_Tmp.State <> adStateClosed Then ar_Tmp.Close
    ar_Tmp.Open StrSql, g_strConn, adOpenKeyset, adLockReadOnly
    If ar_Tmp.RecordCount = 0 Then
        MsgBox "登录用户或密码错误!", 48, "提示"
        Screen.MousePointer = vbDefault
        ar_Tmp.Close
        Exit Sub
    Else
        If Not (IsNull(ar_Tmp!cUserPwd) Or ar_Tmp!cUserPwd = "") Then
            If Trim(ar_Tmp!cUserPwd) <> Trim(txtcPassword.Text) Then
                MsgBox "登录用户或密码错误!", 48, "提示"
                If ar_Tmp.State <> adStateClosed Then ar_Tmp.Close
                Screen.MousePointer = vbDefault
                Exit Sub
            End If
        Else
            If Trim(txtcPassword.Text) <> "" Then
                MsgBox "登录用户或密码错误!", 48, "提示"
                If ar_Tmp.State <> adStateClosed Then ar_Tmp.Close
                Screen.MousePointer = vbDefault
                Exit Sub
            End If
        End If
         
        g_strUserCode = ar_Tmp!cUserCode
        g_strUserName = ar_Tmp!cUserName
        '是否系统管理员
        If ar_Tmp!bUserAdmin = True Then
            g_blnUserAdmin = True
        Else
            g_blnUserAdmin = False
        End If
    End If
    If ar_Tmp.State <> adStateClosed Then ar_Tmp.Close