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

Recommended Answers

All 2 Replies

Is your query correct? What is the issue. please explain

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....

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.