在 vb.net 中使用 ms access 登录表单 [英] login form using ms access in vb.net

查看:52
本文介绍了在 vb.net 中使用 ms access 登录表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ms access 2003 作为数据库为 vb.net 创建登录表单.但它只检查用户名并绕过密码.这意味着如果用户名正确且密码与用户名不一致,用户仍然可以进入系统.这是我的代码:

I'm creating a login form for vb.net using ms access 2003 as database. But it only checks for the username and bypasses the password. Meaning that if the username is correct and the password doesn't jive with the username, the user can still enter the system. Here is my code:

Try

            Dim NoAcc As String
            Dim NoAccmod2 As String
            Dim NoPas As String

            Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\db1.mdb;Jet OLEDB:Database Password=nrew123$%^;")
            Dim cmd As OleDbCommand = New OleDbCommand("Select * from admintable where AdminName= '" & TextBox4.Text & "' ", cn)


            cn.Open()

            rdr = cmd.ExecuteReader
            If rdr.HasRows Then
                rdr.Read()
                NoAcc = rdr("AdminName")
                NoPas = rdr("AdminPass")
                If (TextBox4.Text = NoAcc And TextBox3.Text = NoPas) Then NoAccmod2 = NoAcc

                adminview.Show()



                Me.Hide()
            Else
                MsgBox("Incorrect Username/Password")
                TextBox4.Clear()
                TextBox3.Clear()

            End If
        Catch
            MsgBox("Error logging in, please try again", MsgBoxStyle.Exclamation)
        End Try

我该如何检查用户名和密码?

How do I do it so that it checks both username and password?

推荐答案

您正在使用单行 IF .. THEN :
If (TextBox4.Text = NoAcc And TextBox3.Text = NoPas) Then NoAccmod2 = NoAcc所以下一行将始终被执行:
adminview.Show()

You are using a single line IF .. THEN :
If (TextBox4.Text = NoAcc And TextBox3.Text = NoPas) Then NoAccmod2 = NoAcc so the next line will always be executed:
adminview.Show()

你必须重新排列你的 IF .. THEN 条件

you have to rearrange your IF .. THEN conditions

这篇关于在 vb.net 中使用 ms access 登录表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆