well, this is my problem when i trying to login with account that i set in my database and it show me "Syntax error in string in query expression 'Username = 'admin'AND Password = '1234;'." (Note: the admin and 1234 is the username and password that i save in my database.)
And my database structure are something like this
Staff_ID | Staff_Name | Staff_NRIC | Staff_Gender | Staff_Position | Username | Password
Staff_ID = AutoNumber
Staff_Name = Text
Staff_NRIC = Text
Staff_Gender = Text
Staff_Position = Text (Take note that this field properties (Display Control = Combo box) (Row Source = Administrator;"Manager";"Receptionist")
Username = Text
Password = Text
so hope anyone can lend me a hand on this one. and thanks for those are replying me and helping me.
Private Sub BtmLogIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtmLogIn.Click
Dim Username As String = usernametxt.Text
Dim Password As String = passwordtxt.Text
Dim goahead As Boolean = True
Dim PathToDatabase As String = CurDir() & "\PC Cyber Cafe Staff Database.accdb"
Dim ConnectionStringToDatabase As String
If System.IO.File.Exists(PathToDatabase) = False Then
MsgBox("Database does not exist at this location : " & vbCrLf & PathToDatabase)
Exit Sub
End If
ConnectionStringToDatabase = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & _
PathToDatabase & _
";Persist Security Info=True"
Dim con As New OleDb.OleDbConnection(ConnectionStringToDatabase)
Dim sql As New OleDb.OleDbCommand
sql.CommandText = "SELECT * FROM Staff WHERE Username = '" & Username & "'AND Password = '" & Password & ";"
sql.Connection = con
Dim Da As New OleDb.OleDbDataAdapter(sql)
Dim Dt As New DataTable
Da.Fill(Dt)
Dim Position As String
If Dt.Rows.Count > 0 Then
goahead = True
Position = Dt.Rows(0).Item(4)
If Position = "Administrator" Then
MsgBox("Administrator Account Detected")
FrmManagerMainMenu.Show()
FrmReceptionistMainMenu.Show()
ElseIf Position = "Manager" Then
MsgBox("Manager Account Detected")
FrmManagerMainMenu.Show()
ElseIf Position = "Receptionist" Then
MsgBox("Receptionist Account Detected")
FrmReceptionistMainMenu.Show()
End If
Me.Close()
Else
MsgBox("Login failed! Invalid Username or Password input!")
usernametxt.Clear()
passwordtxt.Clear()
usernametxt.Focus()
End If
End Sub


Sign In
Create Account

Back to top









