0

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

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

It is actually working, but when I try 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() and it worked, but when I tried to login another acc, the value in the previous getName() did not change.

Trevor
  • 7,777
  • 6
  • 31
  • 50
  • @DannyJames there will be an error if i do that. isnt Me.close the default ? –  Sep 12 '17 at 13:30
  • 1
    You say you get a Break Mode window. What does it say? You probably have an exception of some sort. – Chris Dunaway Sep 12 '17 at 13:38
  • An unhandled exception of type 'System.NullReferenceException' occurred in Bunifu_UI_v1.52.dll Additional information: Object reference not set to an instance of an object. –  Sep 12 '17 at 14:03
  • @ChrisDunaway it also say "Your app has entered a break state, but there is no code to show because all threads were executing external code" –  Sep 12 '17 at 14:04
  • @DannyJames : Not if he wants to close the current form. You can only close _**other**_ forms with `formName.Close()`. To close the **current** form you call `Me.Close()`. – Visual Vincent Sep 12 '17 at 14:17
  • @Miku : Check the [**Call Stack Window**](https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger/viewing-the-call-stack-in-visual-studio), it may give you information about what was executing before the external code. – Visual Vincent Sep 12 '17 at 14:19
  • @DannyJames it show nothing :c –  Sep 12 '17 at 14:37

1 Answers1

0

I'm not sure based on what you've said whether this will solve your problem, but try changing the Shutdown Mode:

If you bring up the Properties window for the project, on the Applications Tab you can set the 'Shutdown mode'. The default is when the 'Startup Form Closes'. Change it to 'When the last form closes'.

PerpetualStudent
  • 822
  • 9
  • 17