I'm trying to make a login system on visual basic. I need it to be able to connect to an access database to find the usernames and passwords. I have coded it as follows:
Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
'Purpose: Make a Connection to the database and fill a Dataset with the Account and AccountTrans records
'Create a memory cell to store the drive letter of the USB drive
Dim DriveLetter As Char
'Get the first charatcer, i.e. the drive letter from the application's StartupPath
DriveLetter = Application.StartupPath.Substring(0, 1)
Dim con As New OleDbConnection("Provider=Microsoft.ACE.… Source=" & DriveLetter & ":\greenparkschool\AccessPoints.accdb")
Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM Account WHERE cusername = '" & txtUsername.Text & "'" And cpassword = '" & txtCpassword.Text & "' ", con)
Dim sdr As OleDbDataReader = cmd.ExecuteReader()
'If the record can be queried, Pass verification and open another form.
If (sdr.Read() = True) Then
MessageBox.Show("The user is valid!")
Dim transaction As New transaction
MessageBox.Show("Invalid username or password!")
The problem with this is that it says in the error log that an expression is expected and 'cmd' is not declared. The last section of the SELECT statement seems to comment itself out. What can I do to fix this?