0

I have created a table in my access and i have inserted values in it. I also created a login page on my vb.net form in which i want a matcching field in the table to serve as my UserId and Password to allow user access the next form. I guess there is something i am missing out in my code. I would be glad if anyone can help me with useful hints..Also i wanna check if the fields selected match the database table record.
Below is my code

 Try
            Dim sqlquery As String = "SELECT MatricNo,FirstName FROM matt WHERE MatricNo = '" & txtUsername.Text & "' AND FirstName = '" & txtPassword.Text & "'"
            Dim query As New OleDbCommand(sqlquery, hoc)

            hoc.Open()
            Dim reader As OleDbDataReader = query.ExecuteReader()
            'reader = query.ExecuteReader()
            While reader.Read()
                txtUsername.Text = reader(0)
                txtPassword.Text = reader(1)
            End While
            reader.Close()
            hoc.Close()
            'If txtUsername.Text = "" Or txtPassword.Text = "" Then
            'MsgBox("Enter UserName and Password!")
            'Else
            Form4.Show()
            'End If
        Catch ex As OleDbException
            MsgBox("ERROR!!")
        End Try
3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by jezguitarist30
0

If my analysis is right, you are trying to access to database and you want to check if the
username and the password of the user is correct?

You could acctually just use.

if dr.hasrows then

Msgbox("Correct!")

else

msgbox("Invalid Username or Password")

end if

Or If you really want to get the data and insert it in a textbox.

if dr.hasrows then

  While reader.Read()
            txtUsername.Text = reader(0)
            txtPassword.Text = reader(1)
        End While

else

msgbox("Invalid Username or Password")

end if

reader.close

Hope this helps....

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.