Public Class LoginForm1
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
Dim con As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\ahamdi2\Documents\Visual Studio 2008\Projects\sistemPengesanan\sistemPengesanan\admin.mdf;Integrated Security=True;User Instance=True")
Dim cmd As New SqlCommand("SELECT * FROM info WHERE username = '" & UsernameTextBox.Text & "' AND [password] = '" & PasswordTextBox.Text & "' ", con)
Dim cmd2 As New SqlCommand()
cmd2.CommandText = "update info set tarikh_akhir_guna='" & DateAndTime.Now & "'where username= '" & UsernameTextBox.Text & "'"
con.Open()
Dim sdr As SqlDataReader = cmd.ExecuteReader()
' If the record can be queried, it means passing verification, then open another form.
If (sdr.Read() = True) Then
MessageBox.Show("The user is valid!")
UsernameTextBox.Text = " "
PasswordTextBox.Text = ""
cmd2.ExecuteNonQuery()
Me.Hide()
Form1.Show()
Else
MessageBox.Show("Invalid username or password!")
UsernameTextBox.Text = " "
PasswordTextBox.Text = ""
End If
con.Close()
End Sub