Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. ' Check if username or password is empty
  2. If TextBox1.Text = "" Or TextBox2.Text = "" Then
  3. MessageBox.Show("Username and password are blank", "Authentication Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
  4. ' Both fields was supply
  5. ' Check if user exist in database
  6. ' Connect to DB
  7. Else
  8. Dim conn As New System.Data.OleDb.OleDbConnection()
  9. conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\-------.ult.org.ukhomestudent-------dt_database.accdb"
  10. Try
  11. 'conn.Open()
  12. 'MsgBox("Susscess")
  13. Dim sql As String = "SELECT * FROM tbl_user WHERE username='" & TextBox1.Text & "' AND password = '" & TextBox2.Text & "'"
  14. Dim sqlCom As New System.Data.OleDb.OleDbCommand(sql)
  15. 'Open Database Connection
  16. sqlCom.Connection = conn
  17. conn.Open()
  18.  
  19. Dim sqlRead As System.Data.OleDb.OleDbDataReader = sqlCom.ExecuteReader()
  20.  
  21.  
  22. If sqlRead.Read() Then
  23. AdminMenu.Show()
  24. Me.Hide()
  25. Else
  26.  
  27. ' If user enter wrong username and password combination
  28. ' Throw an error message
  29. MessageBox.Show("Username and Password do not match.", "Authentication Failure", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  30.  
  31. 'Clear all fields
  32. TextBox1.Text = ""
  33. TextBox2.Text = ""
  34.  
  35. 'Focus on Username field
  36. TextBox1.Focus()
  37. End If
  38.  
  39. Catch ex As Exception
  40. MessageBox.Show("Failed to connect to Database..", "Database Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
  41. End Try
  42.  
  43. End If
  44.  
  45.  
  46. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement