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