Hi, below is the code in my login button, yet I'm confused what code to put in logout button. I only know few knowledge about vb.net and I am trying to understand it as much as I can. Thank you for understanding! :)
Public Class Form2
Private OPConStr As String = ("server=localhost;username=root;password=07292021;database=usersaccount")
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim ID As Integer
Using connection As New MySqlConnection(OPConStr),
cmd As New MySqlCommand("SELECT `StudentId` FROM `usersaccount` WHERE `StudentId` = @username AND `Account Password` = @password", connection)
cmd.Parameters.Add("@username", MySqlDbType.VarChar).Value = Username.Text
cmd.Parameters.Add("@password", MySqlDbType.VarChar).Value = Pass.Text
connection.Open()
ID = CInt(cmd.ExecuteScalar())
End Using
If ID = 0 Then
MessageBox.Show("Invalid Username Or Password")
Exit Sub
End If
Using con As New MySqlConnection("server=localhost;username=root;password=07292021;database=logsrecord"),
cmd As New MySqlCommand("Insert into loghistory.logsrecord (StudentID, DateIn, Action) Values (@ID, @In, @Action);", con)
cmd.Parameters.Add("@ID", MySqlDbType.VarChar).Value = ID
cmd.Parameters.Add("@In", MySqlDbType.DateTime).Value = Now()
cmd.Parameters.Add("@Action", MySqlDbType.Int32).Value = 1
con.Open()
cmd.ExecuteNonQuery()
End Using
Form3.Show()
Hide()
End Sub
This is the table in my database:
- StudentID (VarChar)
- In (Datetime)
- Out (Datetime)
- Action (Int)