samedi 28 novembre 2015

Whats wrong with my codes? login forms in VB

whats wrong with my login codes? every time i login the correct username and password it always go to the "incorrect username and password".

can someone help me? just new in vb. thankyou in advance.

               Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
    Dim dbQuery As String = "Select * from tblLogin  where username = '" & txtuse.Text & "'or password = '" & txtPass.Text & "'"
    Dim dbConnection As New MySqlConnection(dbConString)
    Dim dbCmd As New MySqlCommand(dbQuery, dbConnection)
    Dim dbReader As MySqlDataReader
    dbConnection.Open()
    dbReader = dbCmd.ExecuteReader()

    While dbReader.Read()
        If txtuse.Text = dbReader("username") And dbReader("account_type") = "Admin" And txtPass.Text = dbReader("password") Then
            frmAdmin.Show()
            Me.Close()
        ElseIf txtuse.Text <> dbReader("username") And dbReader("account_type") = "Admin" And txtPass.Text = dbReader("password") Then
            MessageBox.Show("Incorrect Username")
        ElseIf txtuse.Text = dbReader("username") And dbReader("account_type") = "Admin" And txtPass.Text <> dbReader("password") Then
            MessageBox.Show("Incorrect Password")
        ElseIf txtuse.Text = dbReader("username") And dbReader("account_type") = "Regular" And txtPass.Text = dbReader("password") Then
            frmRegular.Show()
            Me.Close()
        ElseIf txtuse.Text <> dbReader("username") And dbReader("account_type") = "Regular" And txtPass.Text = dbReader("password") Then
            MessageBox.Show("Incorrect Username")
        ElseIf txtuse.Text = dbReader("username") And dbReader("account_type") = "Regular" And txtPass.Text <> dbReader("password") Then
            MessageBox.Show("Incorrect Password")
        Else
            MessageBox.Show("Incorrect Password and Username")
        End If
    End While
End Sub

Aucun commentaire:

Enregistrer un commentaire