Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
  2.         If Not (txtUsername.Text = "" Or txtPassword.Text = "") Then 'check if txtbox is empty
  3.            If varCounter = 4 Then 'check if number of tries is 4
  4.                MsgBox("You have reached the allowed number of tries. The program is now shutting down.", MsgBoxStyle.Exclamation)
  5.                 Me.Close()
  6.             Else
  7.                 connLogin.Open() 'Open database
  8.                'read from database
  9.                Dim connLIcmd As New SqlCommand("SELECT Logn_Username, Logn_Password FROM User_Login WHERE Logn_Username = '" & txtUsername.Text & "' AND Logn_Password='" & txtPassword.Text & "'", connLogin.Conn)
  10.                 Dim r As SqlDataReader = connLIcmd.ExecuteReader()
  11.  
  12.                 If r.HasRows = 0 Then
  13.                     MsgBox("Either username or password is incorrect. Please try again.", MsgBoxStyle.Exclamation) 'display error msg
  14.                    r.Close() 'close reader
  15.                    varCounter += 1 'add 1 to counter
  16.                    connLogin.Close() 'close database
  17.  
  18.                     txtUsername.Text = "" 'reset login form
  19.                    txtPassword.Text = ""
  20.                     txtUsername.Focus()
  21.                 Else
  22.                     varCounter = 0 'reset counter
  23.                    r.Close() 'close reader
  24.                    connLogin.Close() 'close database
  25.  
  26.                     txtUsername.Text = "" 'reset login form
  27.                    txtPassword.Text = ""
  28.                     txtUsername.Focus()
  29.  
  30.                     'hide login form and show main form
  31.                    Dim frmCopy As New frmMain
  32.                     frmCopy.Owner = Me
  33.                     frmCopy.Show()
  34.                     Me.Hide()
  35.                 End If
  36.             End If
  37.         Else
  38.             MsgBox("Please fill in the required fields.", MsgBoxStyle.Exclamation) 'display error msg
  39.            varCounter += 1
  40.         End If
  41.     End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement