Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6902011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:44:42+00:00 2026-05-27T07:44:42+00:00

this is the event table that records all the status(IN/OUT): +————————————————–+—————–+ | Event_ID |

  • 0

this is the event table that records all the status(IN/OUT):

+--------------------------------------------------+-----------------+
| Event_ID | User_BannerID  | Group_ID | Timestamp | Status | Creator|
+----------+----------------+----------+-----------+--------+--------+
|          |                |          |           |        |        |
|          |                |          |           |        |        |
+----------+----------------+----------+-----------+--------+--------+ 

So am making a sign in-out program using vb.net and mysql. i was wondering if theres a code i can put in somewhere that will be like if a user opens the application he/she must signin before they can signout and if they open the application and they’ve already signed in, they cant signin again they must signout before they can sign out again.

Imports MySql.Data.MySqlClient
Imports System.Data

Public Class frmMain
    Private myConnString As String
    Private myUserID As String

    Public WriteOnly Property connectionString() As String
        Set(ByVal value As String)
            myConnString = value
        End Set
    End Property

    Public WriteOnly Property UserID() As String
        Set(ByVal value As String)
            myUserID = value
        End Set
    End Property

    Private Sub refreshStatus(ByRef statusView As DataGridView)
        Dim conn As New MySqlConnection
        Dim myCommand As New MySqlCommand
        Dim myAdapter As New MySqlDataAdapter
        Dim myData As New DataTable
        Dim SQL As String


        SQL = "SELECT CONCAT(u.lastname, ', ', u.firstname) AS Name, ug.group_name AS Class, DATE_FORMAT(e.timestamp,'%b %d %Y - %r')AS DateTime, e.status AS Status " _
             & "FROM event e, user u, user_group ug " _
             & "WHERE(e.user_bannerid = u.user_bannerid) " _
             & "AND e.group_id = ug.group_id " _
             & "AND ug.user_bannerid = ?userID " _
             & "AND event_id IN " _
             & "( " _
             & "Select MAX(e.event_id) " _
             & "FROM event e " _
             & "GROUP BY e.user_bannerid " _
             & ") " _
             & "ORDER BY datetime"



        conn.ConnectionString = myConnString

        Try
            conn.Open()

            Try
                myCommand.Connection = conn
                myCommand.CommandText = SQL
                myCommand.Parameters.Add("?userID", myUserID)

                myAdapter.SelectCommand = myCommand
                myAdapter.Fill(myData)

                dgvStatus.DataSource = myData
                dgvStatus.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
            Catch myerror As MySqlException
                MsgBox("There was an error reading from the database: " & myerror.Message)
                End Try
        Catch myerror As MySqlException
            MessageBox.Show("Error connecting to the database: " & myerror.Message)
        Finally
            If conn.State <> ConnectionState.Closed Then conn.Close()
            End Try

    End Sub

    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        cboStatus.Items.Add("In")
        cboStatus.Items.Add("Out")
        cboStatus.SelectedIndex = 0

        dgvStatus.ReadOnly = True
        refreshStatus(dgvStatus)

        Dim conn As New MySqlConnection
        Dim myCommand As New MySqlCommand
        Dim myAdapter As New MySqlDataAdapter
        Dim myData As New DataTable
        Dim SQL As String


        SQL = "SELECT ug.group_id, ug.group_name " _
         & "FROM attendance.user_group ug " _
         & "WHERE user_bannerid = ?userID and level_id is NULL "

        conn.ConnectionString = myConnString

        Try
            conn.Open()

            Try
                myCommand.Connection = conn
                myCommand.CommandText = SQL
                myCommand.Parameters.Add("?userID", myUserID)


                myAdapter.SelectCommand = myCommand
                myAdapter.Fill(myData)

                cboClass.DataSource = myData
                cboClass.DisplayMember = "group_name"
                cboClass.ValueMember = "group_id"
            Catch myerror As MySqlException
                MsgBox("There was an error reading from the database: " & myerror.Message)
            End Try
        Catch myerror As MySqlException
            MessageBox.Show("Error connecting to the database: " & myerror.Message)
        Finally
            If conn.State <> ConnectionState.Closed Then conn.Close()
        End Try
    End Sub

    Private Sub cmdUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUpdate.Click
        Dim conn As New MySqlConnection
        Dim myCommand As New MySqlCommand

        conn.ConnectionString = myConnString

        myCommand.Connection = conn
        myCommand.CommandText = "INSERT INTO event(user_bannerid, group_id, timestamp, status, creator)" _
         & "VALUES(?UserID, ?GroupID, NOW(), ?Status, ?Creator)"

        myCommand.Parameters.Add("?UserID", myUserID)
        myCommand.Parameters.Add("?GroupID", cboClass.SelectedValue)
        myCommand.Parameters.Add("?Status", cboStatus.SelectedItem)
        myCommand.Parameters.Add("?Creator", myUserID)

        Try
            conn.Open()
            myCommand.ExecuteNonQuery()
            MessageBox.Show("Status Successfully Updated")
        Catch myerror As MySqlException
            MsgBox("There was an error updating the database: " & myerror.Message)
        End Try
        refreshStatus(dgvStatus)
    End Sub
    Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click
        Dim oForm As frmLogin
        oForm = New frmLogin()
        frmLogin.Show()
        oForm = Nothing
        Me.Hide()
    End Sub

    Private Sub frmLogin_Click(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
        Dim oForm As frmLogin
        oForm = New frmLogin()
        frmLogin.Show()
        oForm = Nothing
        Me.Hide()
    End Sub
End Class
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:44:43+00:00Added an answer on May 27, 2026 at 7:44 am

    Why not just automatically sign the user out if they are already signed in before signing them in again? You can just tell them (through a messagebox or something) that they have been automatically signed out of their previous session if you discover that they were previously signed in.

    Update

    In reviewing your question and code, I think that you are making life far too difficult for yourself by relying on the activity log to provide the user status. The activity log should just be for recording discrete activities, not for determining the user’s status.

    What I recommend is that you add a status field to the user table. This will always store the user’s current status, in or out.

    When the user opens your application, you will have a simple check: what is the user’s status? If the user is logged in, show the user a Log Out button. If the user is not logged in show them a Log Out button. Don’t let them choose from the dropdown what their status is because I can guarantee they will mess something up.

    If the user is logged in, but wants to log in again, they can press the log out button. You will update the user table with their new status and record the activity, then disable the Log Out button and enable the Log In button. When they press the Log In button, you will update the user status and record the new activity.

    As an option, if the user is currently logged in when they start the app, you can show them (from the activity log or as a separate field in the user record) the last time they logged in so they are not confused about why they are being presented with the logout button.

    Update with specific code

    Private Const STATUS_IN As String = "In"
    Private Const STATUS_OUT As String = "Out"
    
    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
        ' Disable the buttons to start
        btnLogin.Enabled = False
        btnLogout.Enabled = False
    
        Dim sCurrentStatus As String
    
        ' Get the user's current status
        sCurrentStatus = GetUserStatus()
    
        ' And update the buttons based on this status change
        Call UpdateButtonsForStatusChange(sCurrentStatus)
    End Sub
    
    Private Sub UpdateButtonsForStatusChange(sStatus As String)
    
        Dim fLoggedIn As Boolean
    
        ' Determine whether or not the user is logged in based on the status
        fLoggedIn = sStatus.Equals(STATUS_IN, StringComparison.InvariantCultureIgnoreCase)
    
        ' If the user is NOT logged in, enable the login button
        btnLogin.Enabled = Not fLoggedIn
        ' If the user IS logged in, enable the logout button
        btnLogout.Enabled = fLoggedIn
    
    End Sub
    
    Private Sub btnLogin_Click(sender As System.Object, e As System.EventArgs) Handles btnLogin.Click
        ' Indicate that the user is logging in
        Call HandleButtonClick(STATUS_IN)
    End Sub
    
    Private Sub btnLogout_Click(sender As System.Object, e As System.EventArgs) Handles btnLogout.Click
        ' Indicate that the user is logging out
        Call HandleButtonClick(STATUS_OUT)
    End Sub
    
    Private Sub HandleButtonClick(sNewStatus As String)
    
        ' Update the database with the user's new status
        Call UpdateUserStatus(sNewStatus)
        ' And update the buttons based on this status change
        Call UpdateButtonsForStatusChange(sNewStatus)
    
    End Sub
    
    Private Function GetUserStatus() As String
    
        ' ToDo: Add your code to get the user's current status here
    
    End Function
    
    Private Sub UpdateUserStatus(sNewStatus As String)
    
        ' ToDo: Add your code to save the user's current status here
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a HTML table that displays rows of records and has a column
First of all, this is the first time that I use Hibernate so my
I have a database table which records all field changes in all database tables
In my events table there are records that have a daily flag that indicate
$(#table_exams tbody tr).click(function (event) { window.location.href=# +$(this).attr(exam_ID); window.location.href=/medilab/prototypes/exams/edit?examId= + $(this).attr(exam_ID) +&referer= + referer; row_select(this);
I have a table in my postgresql 8.4 database like this: id(serial), event_type_id(id, foreign
This table is used to store sessions (events): CREATE TABLE session ( id int(11)
The code in this event is repeated exactly in two other event handlers. How
Is it possible to handle this event in some way? What happens in terms
I have a string like this: event name|event description|event type|event date|event time|event details, event

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.