newbie question. i have a class where i will get the value of username and password of my login form and pass it to admin form

Public Property getUsername() As String
    Get
        Return Login.username.Text
    End Get
    Set(value As String)
        uname = value
    End Set
End Property
Public Property getPassword() As String
    Get
        Return Login.password.Text
    End Get
    Set(value As String)
        pword = value
    End Set
End Property

and a function getName()

  Public Function getName()
    con.Open()
    Dim sd As New SqlDataAdapter("select * from AdminAcc where Username = '" & getUsername() & "'", con)
    Dim dt As New DataTable
    sd.Fill(dt)
    con.Close()
    getName = dt.Rows(0)(1).ToString()

End Function

i want to display the name of that user in my form so i tried this one

Private Sub AdminM_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    admingreeting.Text = "Hi, " + queryclass.getName()
End Sub

its actually working but when i tried to sign out the application stops and a break mode window appears

Private Sub btnsignout_Click(sender As Object, e As EventArgs) Handles btnsignout.Click
    If MsgBox("Are you sure you want to sign out?", vbQuestion + vbYesNo) = vbYes Then
        Login.Show()
        Me.Close()
    End If
End Sub

i tried using the me.hide(), it worked but when i tried to login another account, the value in the previous getName() didnt change.

Help :( thanks in advance!

Recommended Answers

All 3 Replies

While you can work out how to share more about this break screen/message I want to write about a basic design flaw.

Never store those passwords. This is exactly why so many sites get into trouble so quickly. You never store the password, but it's salted encrypted value. This is well discussed and you never want to teach storing of the password or accept it in an assignment or solution.

More at https://www.google.com/search?q=never+store+the+password+in+a+database

About the value that persists. In your form.open or method that fires when the form gets shown, you add code to change those variables to blank or set the input box contents to blank. This is not automatic. You code this.

oh i forgot to mention, this is actually for our assignment in school and not for work so storing password doesn't matter. But thanks, i'll keep that in mind.
i dont know if the button is the problem or what. i made a new button and place it beside that button (same panel) and it didnt work. is it because of the panel or button? i tried to put it in a different button(same form, different panel) and it worked.

It may be time for the course to be updated. At least you now know why companies leak personal information. Folk were taught badly.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.