Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ' Check if username or password is empty
- If TextBox1.Text = "" Or TextBox2.Text = "" Then
- MessageBox.Show("Username and password are blank", "Authentication Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
- ' Both fields was supply
- ' Check if user exist in database
- ' Connect to DB
- Else
- Dim conn As New System.Data.OleDb.OleDbConnection()
- conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\-------.ult.org.ukhomestudent-------dt_database.accdb"
- Try
- 'conn.Open()
- 'MsgBox("Susscess")
- Dim sql As String = "SELECT * FROM tbl_user WHERE username='" & TextBox1.Text & "' AND password = '" & TextBox2.Text & "'"
- Dim sqlCom As New System.Data.OleDb.OleDbCommand(sql)
- 'Open Database Connection
- sqlCom.Connection = conn
- conn.Open()
- Dim sqlRead As System.Data.OleDb.OleDbDataReader = sqlCom.ExecuteReader()
- If sqlRead.Read() Then
- AdminMenu.Show()
- Me.Hide()
- Else
- ' If user enter wrong username and password combination
- ' Throw an error message
- MessageBox.Show("Username and Password do not match.", "Authentication Failure", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
- 'Clear all fields
- TextBox1.Text = ""
- TextBox2.Text = ""
- 'Focus on Username field
- TextBox1.Focus()
- End If
- Catch ex As Exception
- MessageBox.Show("Failed to connect to Database..", "Database Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
- End Try
- End If
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement