Imports System.Data.SqlClient
Public Class Form1
Private Sub ValidateLogin(ByVal username As String, _
ByVal password As String, ByVal accesslevel As String)
Dim connection As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\accounttlb.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")
Dim sqlstring As String = String.Format("Select username,password,accesslevel from accpw where username = '{0}' and password ='{1}' ", tbusername.Text, tbpassword.Text)
Dim command As New SqlCommand(sqlstring, connection)
Try
connection.Open()
If Not command.ExecuteScalar Is Nothing Then
MessageBox.Show("Right, Logged In")
Me.Hide()
Form2.ShowDialog()
Else
MessageBox.Show("Wrong, Stay out")
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
Me.Close()
Finally
connection.Close()
End Try
End Sub
Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
ValidateLogin(Me.tbusername.Text, Me.tbpassword.Text, Me.tbaccesslevel.Text)
End Sub
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
Me.DialogResult = Windows.Forms.DialogResult.Cancel
Me.Close()
End Sub