Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Data.OleDb
- Public Class Login
- Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles BtnLogin.Click
- provider = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source ="
- 'Change the following to your access database location
- datafile = "C:\Users\Jimmy\Documents\A level\Computer Science\JonLloydData.accdb"
- connString = provider & datafile
- myConnection.ConnectionString = connString
- myConnection.Open()
- 'the query:
- Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM [StaffData] WHERE [StaffID] = '" & TxtUser.Text & "' AND [Password] = '" & TxtPass.Text & "'", myConnection)
- Dim dr As OleDbDataReader = cmd.ExecuteReader
- ' the following variable is hold true if user is found, and false if user is not found
- Dim userFound As Boolean = False
- ' the following variables will hold the user first and last name if found.
- Dim FirstName As String = ""
- Dim LastName As String = ""
- 'if found:
- While dr.Read
- userFound = True
- FirstName = dr("FirstName").ToString
- LastName = dr("LastName").ToString
- End While
- 'checking the result
- If userFound = True Then
- MainMenu.Show()
- MainMenu.LblWelcome.Text = "Welcome " & FirstName & " " & LastName
- Else
- MsgBox("Sorry, username or password not found", MsgBoxStyle.OkOnly, "Invalid Login")
- End If
- End Sub
- Private Sub ExitBtn_Click(sender As Object, e As EventArgs) Handles BtnExit.Click
- ' This makes the exit button in the top right work
- My.Computer.Audio.PlaySystemSound(System.Media.SystemSounds.Beep)
- 'This makes a warning beep when you click it
- Dim Result = MsgBox("Are you sure you would like to exit?", MessageBoxButtons.YesNo)
- If Result = DialogResult.Yes Then
- ' this closes the application
- Application.Exit()
- End If
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement