Advertisement
Guest User

asdasdasdasd

a guest
May 2nd, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. Public Class Form1
  2.  
  3. Dim Connection As New OleDb.OleDbConnection
  4. Dim da As OleDb.OleDbDataAdapter
  5. Dim ds As New DataSet
  6. Dim sql As String
  7.  
  8. Public Sub conStat()
  9.  
  10. If Connection.State = ConnectionState.Open = True Then
  11. lblConStat.Text = "Connection: OPEN"
  12. lblConStat.ForeColor = Color.Green
  13. ElseIf Connection.State = ConnectionState.Closed Then
  14. lblConStat.Text = "Connection: CLOSED"
  15. lblConStat.ForeColor = Color.Red
  16. End If
  17.  
  18. End Sub
  19.  
  20. Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  21.  
  22. Dim dbProvider As String
  23. Dim dbSource As String
  24. Dim MyFolderPath As String
  25. Dim TheDatabase As String
  26. Dim FullDatabasePath As String
  27.  
  28. dbProvider = "PROVIDER=Microsoft.Ace.OLEDB.12.0;"
  29. TheDatabase = "\Database Questions.accdb"
  30. MyFolderPath = "H:\Computing\Chapters\Chapter 5\COMPONENT 2"
  31. FullDatabasePath = MyFolderPath & TheDatabase
  32.  
  33. dbSource = "Data Source = " & FullDatabasePath
  34.  
  35. Connection.ConnectionString = dbProvider & dbSource
  36. Connection.Open()
  37.  
  38. conStat()
  39.  
  40. End Sub
  41.  
  42. Private Sub lblUsername_Click(sender As Object, e As EventArgs) Handles lblUsername.Click
  43.  
  44. End Sub
  45.  
  46. Private Sub txtUsername_TextChanged(sender As Object, e As EventArgs) Handles txtUsername.TextChanged
  47.  
  48. End Sub
  49.  
  50. Private Sub lblPassword_Click(sender As Object, e As EventArgs) Handles lblPassword.Click
  51.  
  52. End Sub
  53.  
  54. Private Sub txtPassword_TextChanged(sender As Object, e As EventArgs) Handles txtPassword.TextChanged
  55.  
  56. End Sub
  57.  
  58. Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click
  59.  
  60. Dim strUsername = txtUsername.Text
  61. Dim strPassword = txtPassword.Text
  62.  
  63. If Connection.State = ConnectionState.Open = True Then
  64.  
  65. sql = "SELECT Password FROM USERPASS WHERE Username= '" & strUsername & "'"
  66. da = New OleDb.OleDbDataAdapter(sql, Connection)
  67. da.Fill(ds, "Credentials")
  68.  
  69. Try
  70. If ds.Tables("Credentials").Rows(0).Item(0) = strPassword Then
  71. MsgBox("Login Successful")
  72. Else
  73. MsgBox("Login failed, incorrect password")
  74. End If
  75. Catch ex As Exception
  76. MsgBox("Please enter a valid username and password.")
  77. End Try
  78.  
  79. ds.Clear()
  80.  
  81.  
  82. ElseIf Connection.State = ConnectionState.Closed = True Then
  83. MsgBox("You must establish a connection before you login.")
  84. End If
  85.  
  86. End Sub
  87.  
  88. Private Sub btnFPassword_Click(sender As Object, e As EventArgs) Handles btnFPassword.Click
  89.  
  90. Try
  91.  
  92. If ForgottenPassword.Visible Then
  93. ForgottenPassword.Hide()
  94. Else
  95. ForgottenPassword.Show()
  96. End If
  97.  
  98. Me.Hide()
  99.  
  100. Catch ex As Exception
  101. End Try
  102.  
  103. End Sub
  104.  
  105. Private Sub btnCloseConnection_Click(sender As Object, e As EventArgs) Handles btnCloseConnection.Click
  106.  
  107. Connection.Close()
  108. conStat()
  109.  
  110. End Sub
  111.  
  112. Private Sub btnOpenConnection_Click(sender As Object, e As EventArgs) Handles btnOpenConnection.Click
  113.  
  114. Connection.Open()
  115. conStat()
  116.  
  117. End Sub
  118. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement