能否给我个登陆的代码

解决方案 »

  1.   

    Option ExplicitPrivate Conn As New ADODB.Connection
    Private Rs As New ADODB.RecordsetPrivate Sub Command1_Click()
    Unload Me
    End SubPrivate Sub Command2_Click()
    If Text1.Text = "" Then
    MsgBox "请输入用户名。"
    Exit Sub
    End If
    Dim strConn As String
    Dim sqlstr As String
        
        strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\销售库存1\data\sale&stock.mdb;Persist Security Info=False"
        Conn.CursorLocation = adUseClient
        'CursorLocation adUseClient
         Conn.Open strConn
        sqlstr = "Select * from userLEVEL where username=""" + Trim(Text1.Text) + """;"
        If Rs.State <> adStateClosed Then Rs.Close
        Rs.Open sqlstr, Conn, adOpenStatic, adLockOptimistic
        
        If Rs.RecordCount < 1 Then
        MsgBox "没有这个用户,请重新输入。"
        Conn.Close
        Exit Sub
        End If
        
        If Rs.Fields("password") <> Trim(Text2.Text) Then
        MsgBox "密码错误,请重新输入。"
        Text2.SetFocus
        Conn.Close
        Exit Sub
        End If
        
        If Rs.Fields("level") < 4 Then frmmain.munRk.Visible = True
        If Rs.Fields("level") < 3 Then frmmain.munCk.Visible = True
        If Rs.Fields("level") < 2 Then frmmain.sumcal.Visible = True
        
        frmmain.Show
        Unload Me
                 End Sub
      

  2.   

    Private Sub que_Click()If Trim(nm.Text) = "" Then
    MsgBox "请输入用户名!", vbDefaultButton1, "警告"
    nm.SetFocus
    End If
    Dim mysql As String
    mysql = "select psw from usertab where name='" + nm.Text + "'"
    Dim rt As ADODB.Recordset
    Set rt = New ADODB.Recordset
    rt.Open mysql, conn, adOpenStatic, adLockOptimistic
    If rt.RecordCount > 0 Then
        If rt.Fields("psw") <> Trim(psw.Text) Then
        MsgBox ("密码错误"), , "警告"
        Exit Sub
        End If
      
       
       ElseIf rt.RecordCount < 1 Then
        MsgBox (" 无此用户"), , "警告"
        nm.Text = ""
        psw.Text = ""
        nm.SetFocus
        Exit Sub
        
    End If
    Form2.Show
    Unload Me
    Form2.Height = Screen.Height
    Form2.Width = Screen.Width
        End Sub
    密码输对了也回提示密码错误???
      

  3.   

    debug.print rt.Fields("psw"),len(rt.Fields("psw")),psw.Text,len(psw.Text)
    看看你得到的跟你输入的是否一致