When the user clicked the ShowInfoBtn, it should display all the info of the user from the database in the textboxes given. Here’s the code:
Imports MySql.Data.MySqlClient
Public Class Profile
Dim conn As MySqlConnection
Dim COMMAND As MySqlCommand
Public Property LoggedInUserID As Integer
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Me.Hide()
Dashboard.Show()
End Sub
Private Sub ShowInfoBtn_Click(sender As Object, e As EventArgs) Handles ShowInfoBtn.Click
conn = New MySqlConnection("server=localhost;userid=root;password='';database=glucocheck")
Try
conn.Open()
Dim query As String = "SELECT Name, Email, DOB, Gender, Age, Type, Weight, Height FROM accounts WHERE ID = @UserID"
COMMAND = New MySqlCommand(query, conn)
COMMAND.Parameters.AddWithValue("@UserID", LoggedInUserID) ' Assuming LoggedInUserID is set elsewhere in your program
Dim reader As MySqlDataReader = COMMAND.ExecuteReader()
If reader.Read() Then
' Populate textboxes with data
NameTb.Text = reader("Name").ToString()
EmailTb.Text = reader("Email").ToString()
BoDTb.Text = reader("DOB").ToString()
GenderTb.Text = reader("Gender").ToString()
AgeTb.Text = reader("Age").ToString()
TypeTb.Text = reader("Type").ToString()
WeightTb.Text = reader("Weight").ToString()
HeightTb.Text = reader("Height").ToString()
' Calculate BMI
Dim weight As Double = Double.Parse(reader("Weight").ToString())
Dim height As Double = Double.Parse(reader("Height").ToString())
Dim bmi As Double = weight / (height * height)
BMITb.Text = Math.Round(bmi, 2).ToString()
Else
MessageBox.Show("No user data found for the logged-in user.")
End If
reader.Close()
Catch ex As Exception
MessageBox.Show("Error: " & ex.Message)
Finally
conn.Close()
End Try
End Sub
End Class
I tried to debuggging the LoggedInUserID in the LandingPage and the Dashboard but nothing happened. It sill says that no user data found..
New contributor
Andrei de Chavez is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.