0

好的,所以这是我在 vb.net 中工作的程序的一部分,它应该做的是进入我的 MYSQL 数据库并检查用户输入的内容与数据库中的用户名/密码匹配(简单登录)但它是不工作,它在第一个 if 语句处停止,我不知道为什么,但每次都会遇到问题。我在messagebox的每一行都输入了以解决问题,所以我知道if语句有问题

    Dim rdr As MySqlDataReader = Nothing
    Myconnection = "Server=LocalHost; database=vb; user=root; password=tro63jans; "
    db_con.ConnectionString = Myconnection
    Dim cmd As New MySqlCommand("SELECT * FROM login", db_con)


    Try
        db_con.Open()
        rdr = cmd.ExecuteReader()

        Dim found As Boolean = False

        While rdr.Read()

            If username.ToUpper() = DirectCast(rdr("username"), String) Then

                If password = DirectCast(rdr("password"), String) Then

                    found = True
                    MessageBox.Show("you are log in")
                    Exit While

                Else

                    MessageBox.Show("username and password do not match", "Error")
                    txtpassword.Focus()

                End If

                If found Then

                    MessageBox.Show("user name not found", "error")
                    txtusername.Focus()
                    txtpassword.Focus()
                    Exit While

                End If

            Else

                If found Then
                    MessageBox.Show("User name not found", "error")
                    txtusername.Focus()

                End If
            End If
        End While
4

0 回答 0