This is not a homework of mine and i had never tried ms access database with vb so i just gave it a shot. so this is my first time and i am just trying not asking anyone to complete my homework. I have been searching for this a lot on internet but couldn't find a solution to this so i decided to ask this question here.
i have this sql code. what i want to do is that create a basic login form where users puts it's username in the UsernameTextbox and Password in the PasswordTextbox. If the the information match then a message box appears saying that the user is valid and if the information does not exist, a mesage box appears saying the users is not valid.
now everytime i execute(run) the code, i come up with this error
Syntax error (missing operator) in query expression ''UserName' = 'Admin' 'PassWord' = 'testing123''.
the field names(UserName, PassWord) are also correct
they are same as in the database.
the information put in the username and password textbox are correct and they match the information on the database. But i dont know why this error comes up.
my code module is the following:
Imports System.Data.OleDb Public Class LoginForm1 ' Cancel button Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click Me.Close() End Sub 'ok button Private Sub ok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ok.Click Dim con As New OleDbConnection("Provider=Microsoft.jet.oledb.4.0;data source=C:\Documents and Settings\Saurabh\My Documents\Versa Server 2008.mdb") Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM ['Login'] WHERE 'UserName' = '" & UsernameTextbox.Text & "'" & " 'PassWord' = '" & PasswordTextbox.Text & "'", con) con.Open() 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 mainForm As New Form mainForm.Show() Me.Hide() Else MessageBox.Show("Invalid username or password!") End If End Sub End Class
I am sure that i am making a silly mistake but still i dont know what is wrong so can anyone please help me out a little.
i am new to ms access and vb.net
any help will be appreciated.