Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Imports System.Data.OleDb
  2. Public Class Login
  3.     Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles BtnLogin.Click
  4.         provider = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source ="
  5.         'Change the following to your access database location
  6.        datafile = "C:\Users\Jimmy\Documents\A level\Computer Science\JonLloydData.accdb"
  7.         connString = provider & datafile
  8.         myConnection.ConnectionString = connString
  9.  
  10.         myConnection.Open()
  11.         'the query:
  12.        Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM [StaffData] WHERE [StaffID] = '" & TxtUser.Text & "' AND [Password] = '" & TxtPass.Text & "'", myConnection)
  13.         Dim dr As OleDbDataReader = cmd.ExecuteReader
  14.         ' the following variable is hold true if user is found, and false if user is not found
  15.        Dim userFound As Boolean = False
  16.         ' the following variables will hold the user first and last name if found.
  17.        Dim FirstName As String = ""
  18.         Dim LastName As String = ""
  19.  
  20.         'if found:
  21.        While dr.Read
  22.             userFound = True
  23.             FirstName = dr("FirstName").ToString
  24.             LastName = dr("LastName").ToString
  25.         End While
  26.  
  27.         'checking the result
  28.        If userFound = True Then
  29.             MainMenu.Show()
  30.             MainMenu.LblWelcome.Text = "Welcome " & FirstName & " " & LastName
  31.         Else
  32.             MsgBox("Sorry, username or password not found", MsgBoxStyle.OkOnly, "Invalid Login")
  33.         End If
  34.  
  35.  
  36.     End Sub
  37.  
  38.     Private Sub ExitBtn_Click(sender As Object, e As EventArgs) Handles BtnExit.Click
  39. ' This makes the exit button in the top right work
  40.            My.Computer.Audio.PlaySystemSound(System.Media.SystemSounds.Beep)
  41. 'This makes a warning beep when you click it
  42.            Dim Result = MsgBox("Are you sure you would like to exit?", MessageBoxButtons.YesNo)
  43.             If Result = DialogResult.Yes Then
  44. ' this closes the application
  45.                Application.Exit()
  46.             End If
  47.         End Sub
  48.     End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement