Hello,

I wrote some codes for student login. the codes checks for the "username", "password" as well as their type of "status", from the database. once this input are met, the student logs in successful, otherwise a message pops up.

The problem i encountered is this, i have 11 student records in my database and only the first 6 students can login successfully. the remaining 5 students cannot login. Despite entering the correct username, password and status for the last 5 students in the database, the message "Invalid username and password" comes up. I don't know where my code went wrong or maybe i didn't write the right codes to accept all student records as well as new ones.

Here's my code for the login:

Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click

        If txtUsername.Text = "" Then
            MessageBox.Show("Please enter your Student Id to login", "South City College", MessageBoxButtons.OK, MessageBoxIcon.Error)
            txtUsername.Focus()
        ElseIf txtPassword.Text = "" Then
            MessageBox.Show("Please enter your Password to login", "South City College", MessageBoxButtons.OK, MessageBoxIcon.Error)
            txtPassword.Focus()
        ElseIf cboStatus.Text = "" Then
            MessageBox.Show("Please select your status to login", "South City College", MessageBoxButtons.OK, MessageBoxIcon.Error)

        Else

            Dim conLogin As New OleDb.OleDbConnection("PROVIDER=Microsoft.ACE.Oledb.12.0; Data Source = D:\DB2Test.accdb")
            Dim commLogin As New OleDb.OleDbCommand("SELECT Student.Student_ID, Student.Password, Student.Status FROM Student WHERE Student_ID = @Username AND Password = @password AND Status = @status", conLogin)

            Dim usernameParam As New OleDb.OleDbParameter("@username", Me.txtUsername.Text)
            Dim passwordParam As New OleDb.OleDbParameter("@password", Me.txtPassword.Text)
            Dim statusParam As New OleDb.OleDbParameter("@status", Me.cboStatus.SelectedItem)

            commLogin.Parameters.Add(usernameParam)
            commLogin.Parameters.Add(passwordParam)
            commLogin.Parameters.Add(statusParam)

            commLogin.Connection.Open()

            Dim reader As OleDb.OleDbDataReader = commLogin.ExecuteReader()

            If reader.HasRows Then
                MessageBox.Show("Login successful!", "South City College", MessageBoxButtons.OK, MessageBoxIcon.Information)
                frmDB2Test.Show()
                Me.Hide()

            Else
                MessageBox.Show("Invalid Student Data! Please enter correct Student Data.", "South City College", MessageBoxButtons.OK, MessageBoxIcon.Error)
                txtUsername.Clear()
                txtPassword.Clear()
                cboStatus.Text = ""
                txtUsername.Focus()

            End If

            commLogin.Connection.Close()

        End If

    End Sub

Hello,

I wrote some codes for student login. the codes checks for the "username", "password" as well as their type of "status", from the database. once this input are met, the student logs in successful, otherwise a message pops up.

The problem i encountered is this, i have 11 student records in my database and only the first 6 students can login successfully. the remaining 5 students cannot login. Despite entering the correct username, password and status for the last 5 students in the database, the message "Invalid username and password" comes up. I don't know where my code went wrong or maybe i didn't write the right codes to accept all student records as well as new ones.

Here's my code for the login:

Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click

        If txtUsername.Text = "" Then
            MessageBox.Show("Please enter your Student Id to login", "South City College", MessageBoxButtons.OK, MessageBoxIcon.Error)
            txtUsername.Focus()
        ElseIf txtPassword.Text = "" Then
            MessageBox.Show("Please enter your Password to login", "South City College", MessageBoxButtons.OK, MessageBoxIcon.Error)
            txtPassword.Focus()
        ElseIf cboStatus.Text = "" Then
            MessageBox.Show("Please select your status to login", "South City College", MessageBoxButtons.OK, MessageBoxIcon.Error)

        Else

            Dim conLogin As New OleDb.OleDbConnection("PROVIDER=Microsoft.ACE.Oledb.12.0; Data Source = D:\DB2Test.accdb")
            Dim commLogin As New OleDb.OleDbCommand("SELECT Student.Student_ID, Student.Password, Student.Status FROM Student WHERE Student_ID = @Username AND Password = @password AND Status = @status", conLogin)

            Dim usernameParam As New OleDb.OleDbParameter("@username", Me.txtUsername.Text)
            Dim passwordParam As New OleDb.OleDbParameter("@password", Me.txtPassword.Text)
            Dim statusParam As New OleDb.OleDbParameter("@status", Me.cboStatus.SelectedItem)

            commLogin.Parameters.Add(usernameParam)
            commLogin.Parameters.Add(passwordParam)
            commLogin.Parameters.Add(statusParam)

            commLogin.Connection.Open()

            Dim reader As OleDb.OleDbDataReader = commLogin.ExecuteReader()

            If reader.HasRows Then
                MessageBox.Show("Login successful!", "South City College", MessageBoxButtons.OK, MessageBoxIcon.Information)
                frmDB2Test.Show()
                Me.Hide()

            Else
                MessageBox.Show("Invalid Student Data! Please enter correct Student Data.", "South City College", MessageBoxButtons.OK, MessageBoxIcon.Error)
                txtUsername.Clear()
                txtPassword.Clear()
                cboStatus.Text = ""
                txtUsername.Focus()

            End If

            commLogin.Connection.Close()

        End If

    End Sub

Try to retrieve first in you database access using the SQL to check wheres the problem and also check your field data type.

SELECT Student.Student_ID, Student.Password, Student.Status FROM Student WHERE Student_ID ='Username' AND Password ='password' AND Status ='status'

Try to retrieve first in you database access using the SQL to check wheres the problem and also check your field data type.

SELECT Student.Student_ID, Student.Password, Student.Status FROM Student WHERE Student_ID ='Username' AND Password ='password' AND Status ='status'

Hi Ryan, this one seems not to find anything entered in the username, password and status textbox. It keeps giving the message "Invalid Username and Password" anytime I enter correct login details.

The "@" symbols seems to work for it, but still it sees only some records and the rest not working. I meant this one:

"SELECT Student.Student_ID, Student.Password, Student.Status FROM Student WHERE Student_ID = @Username AND Password = @password AND Status = @status"

some one help me about login in visual basic using datab ase acces

Of course I suppose the student data has been entered correctly, but I can't see the need for entering a third field: status. If you want to assure the password you may constrain passwords to those containing both capital and lower letters and special characters like !,$,%, and so on. The third status field, then, can be obtained from the database when the username and password have been entered correctly.

well acording to me i removed the @ symbols and everything turned out awesomeSuccess

mine is not reading the correct infoi don't know why but its not reading the correct password what did I do Wrong!!!!

     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
                                If User.Text = "" Then
        MessageBox.Show("Please enter your Username to login", "Stjohn's chikwaka feed back", MessageBoxButtons.OK, MessageBoxIcon.Error)
        User.Focus()
    ElseIf email.Text = "" Then
        MessageBox.Show("Please enter your Email to login", "Stjohn's chikwaka feed back", MessageBoxButtons.OK, MessageBoxIcon.Error)
        email.Focus()
    ElseIf password.Text = "" Then
        MessageBox.Show("Please enter your Password to login", "Stjohn's chikwaka feed back", MessageBoxButtons.OK, MessageBoxIcon.Error)
        password.Focus()
    Else
        Dim conLogin As New OleDb.OleDbConnection("PROVIDER=Microsoft.ACE.Oledb.12.0; Data Source =C:\Users\chizhanjet4green\Documents\login.accdb")
        Dim commLogin As New OleDb.OleDbCommand("SELECT login.Username, login.Email, login.Password FROM Login WHERE user = Username AND email= Email  AND password= Password", conLogin)
        Dim userParam As New OleDb.OleDbParameter("Username", Me.User.Text)
        Dim emailParam As New OleDb.OleDbParameter("Email ", Me.email.Text)
        Dim PasswordParam As New OleDb.OleDbParameter("Password", Me.password.Text)
        commLogin.Parameters.Add(UserParam)
        commLogin.Parameters.Add(emailParam)
        commLogin.Parameters.Add(PasswordParam)

        commLogin.Connection.Open()

        Dim reader As OleDb.OleDbDataReader = commLogin.ExecuteReader()

        If reader.HasRows Then
            MessageBox.Show("Login successful!", "Stjohn's chikwaka feed back", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Welcome_To_The_Main_Menu_Of_The_System.Show()
            Me.Hide()
        Else
            MessageBox.Show("Invalid Details enter invalid! Please enter correct login data.", "Stjohn's chikwaka feed back", MessageBoxButtons.OK, MessageBoxIcon.Error)
            User.Clear()
            email.Clear()
            password.Clear()
            User.Focus()
        End If
        commLogin.Connection.Close()
    End If

End Sub
commented: The only wrong step I see is burying your new discussion under 7 years of dust. +15
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.