How to read per row in a table in mySQL as the database? i want each username when they login, they will go to their respective forms. Like for example, there are 3 users and each user have their different forms. can someone help me with this... thank you!

This is my code:

Dim conn As MySqlConnection
Dim myCommand As New MySqlCommand
Dim dr As MySqlDataReader

conn = New MySqlConnection("server=localhost; Uid=myid; Pwd=mypass; database=useraccounts")
myCommand = New MySqlCommand("SELECT * FROM useraccount where username='" & txtUsername.Text.ToLower & "'", conn)


Try
conn.Open()

dr = myCommand.ExecuteReader
dr.Read()

If txtUsername.Text.ToLower.Equals(dr(0)) And txtPassword.Text.Equals(dr(1)) Then
MsgBox("Welcome!", MsgBoxStyle.Information, "login Successful")
frmAdmin.Show()
Me.Hide()
Else
MsgBox("Password didn't match the username", MsgBoxStyle.Critical, "Login Unsuccessful")
txtbox()
End If

conn.Close()
conn.Dispose()

Catch myerror As MySqlException
MsgBox("Username does not exist", MsgBoxStyle.Critical, "Login Unsuccessful")
txtbox()

Catch myerror As Exception
MsgBox(myerror.ToString)
Environment.Exit(0)

End Try

Edited 6 Years Ago by selle05: n/a

If you have only a few users, you could use something like this:

Dim oFormForJohn As Form2 ' This is for John
Dim oFormForJane As Form3 ' This is for Jane

Select txtUsername.Text.ToLower()
    Case "john"
        oFormForJohn = New Form2
        ' Set properties if form has any
        oFormForJohn.ShowDialog() ' Modal, use Show() for modeless
        ' After exiting the form, dispose it
        oFormForJohn = Nothing
    Case "jane"
        oFormForJane = New Form3
        ' Set properties if form has any
        oFormForJane.ShowDialog() ' Modal, use Show() for modeless
        ' After exiting the form, dispose it
        oFormForJohn = Nothing
    Case Else
        ' Open default form?
End Select

after successful login.

If you customize a single form per user:

Dim oForm As Form2 ' This is for all users but the user is passed as a form's property

oForm = New Form2
' Set user
oForm.UserName = TextBox1.Text
oForm.ShowDialog() ' Modal, use Show() for modeless
' After exiting the form, dispose it
oForm = Nothing

in this case Form2 would have a property called UserName or public variable Public UserName As String .

HTH

Hi! Nice to hear that you got answer to your problem. Could you please mark the thread as solved. Thank you!

This question has already been answered. Start a new discussion instead.