Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi. Below is the code for my login button. I am confused on what code to input for logout button. I'm planning to record the login date and logout date in same row. Thank you! :)

Btw, this is my database table:
- Student ID(VarChar)
- DateIn (DateTime)
- DateOut (DateTime)
- Action (Int)

What I have tried:

Public Class Form2

    Private OPConStr As String = ("server=localhost;username=root;password=;database=usersaccount")


    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Label5.Text = DateAndTime.Now.ToString("MMMM dd, yyyy hh:ss:tt")
    End Sub

    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=;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
Posted
Updated 4-Nov-21 3:39am
v2
Comments
Richard Deeming 4-Nov-21 5:52am    
Myln29 4-Nov-21 5:57am    
Yes, sir! Noted. Thank you so much!
Myln29 4-Nov-21 6:00am    
Can you give me idea about the logout button?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900