最好能讲解一下,数据库是access的

解决方案 »

  1.   

    '一个简单的用户口令登录验证的例子
    '包含了用户管理的一些概念Public Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As LongType UserInfo        '登录用户信息自定义变量
        UserID      As String
        UserName    As String
        UserJob     As String
    End Type
    Public LovelyUser   As UserInfo '记录登录用户名的信息,用于显示和验证权限
    '***************************************************************************************
    '功  能:   获取登录用户信息
    '编写人:
    '参  数:
    '返回值:   自定义用户变量,存储用户信息
    '***************************************************************************************
    Function GetUser() As UserInfo
        Dim usr As String
        Dim aa As String
        Dim Temp As String
        Dim AdoRs As New ADODB.Recordset
        Dim strSQl As String
        
        '获得登录域用户名
        usr = Space(256)
        aa = GetUserName(usr, 256)
        Temp = Left(RTrim(usr), Len(RTrim(usr)) - 1)
        
        '获得权限表中信息
        strSQl = "select * from persons where UserID='" & Temp & "'"
        AdoRs.Open strSQl, gadoConn, adOpenKeyset, adLockReadOnly
        If Not AdoRs.EOF And Not AdoRs.BOF Then
            GetUser.UserID = Trim(Temp)
            GetUser.UserName = Trim(AdoRs!UserName)
            GetUser.UserJob = Trim(AdoRs!UserJob)
        Else
            MsgBox "您没有使用此系统的权限!", vbOKOnly, "警告!"
            GetUser.UserID = Temp
            GetUser.UserName = "NoRight"
            Exit Function
        End If
    End Function
      

  2.   

    if 输入的编码=库存编码 AND 输入用户名=库存用户名 then    进入else
       密码错误
    endif
      

  3.   

    我写了这样一个
    Private Sub command1_click()
    Dim mrs As adodb.Recordset
    txtsql = "select*from oper where 用户名='" & Trim$(Text1(0).Text) & "'" & " and 口令='" & Trim$(Text1(1).Text) + "'"
    Set mrc = exesql(txtsql)
    If mrc.recordcount = 0 Then
    n = n + 1
    If n < 3 Then
    MsgBox "没有这个用户,继续登录", vbOKOnly + vbExclamation, "信息提示"
    Text1(0).Text = ""
    Text1(1).Text = ""
    Text1(0).SetFocus
    Else
    MsgBox "以登录失败三次,退出系统", vbOKOnly + vbExclamation, "信息提示"
    mrc.Close
    Unload Me
    End If
    userlevel = Trim(mrc.fields("级别"))
    mrc.Close
    Unload Me
    Main.Show
    End If
    End Sub
    为什么运行时说As adodb.Recordset用户定义类型未定义,怎么改啊!?答完了就改分 啊
      

  4.   

    set mrc=new adodb.recordset
    在Set mrc = exesql(txtsql) 前面
      

  5.   

    呵呵
    如果
    text1(0).text="' or ''=''"
    text1(1).text="' or ''=''"
    试试你的程序看验证能不能通过。
      

  6.   

    sorry 应该是
    text1(0).text="' or ''='"
    text1(1).text="' or ''='"
      

  7.   

    我想你的数据库连接和打开应该在 exesql(txtsql)函数里做了,然后将recordset返回给了mrc.
    问题是你前面一句是Dim mrs As adodb.Recordset,mrs和mrc是否是一个记录集?既然没有定义,set mrc怎么行?建议在函数值返回前先加一句set mrc(mrs)=new adodb.recordset.
    第一个end if 前好象还应该加上一个else才对。
    还有select语句没有必要那么复杂吧?txtsql = "select * from oper where 用户名='" & Trim$(Text1(0).Text) & "'" & " and 口令=" & Trim$(Text1(1).Text) 就可以了呀!