Hi All,
I am starting out at VB.NET and almost immediately I am stuck on what seems to be such a simple problem....
I have created a MySQL database and have created a login form in VB.NET. The connection is fine and provided the user enters the correct login details verything works great up to this point.
The problem is,... once the user has entered his details (successfully) into the login screen the main application should start up. To do this I have created a second form with menu bar etc, etc,. However, the new form only temporarily displays and then vanishes. I have created a line break in the " Private Sub frm_Main_Load...." procedure and it is definately being called, but seems to pass control back to the calling form (login screen) instantly and then exits the application.
My apologies for such a fundamental question, but I can't seem to find the solution. I have come across a comment that says that the "frm_Main.Show()" call is "not persistent", but frankly this means little to me and searching for details regarding this comment is simply confusing.
I am pasting the code from the two forms below, any advice / help / assistance would be much appreciated:
frm_login code
frm_Main code
I thought that once the control has been passed to frm_Main that the program should run in this class until the form control is closed?!?!?
Regards
Rob
I am starting out at VB.NET and almost immediately I am stuck on what seems to be such a simple problem....
I have created a MySQL database and have created a login form in VB.NET. The connection is fine and provided the user enters the correct login details verything works great up to this point.
The problem is,... once the user has entered his details (successfully) into the login screen the main application should start up. To do this I have created a second form with menu bar etc, etc,. However, the new form only temporarily displays and then vanishes. I have created a line break in the " Private Sub frm_Main_Load...." procedure and it is definately being called, but seems to pass control back to the calling form (login screen) instantly and then exits the application.
My apologies for such a fundamental question, but I can't seem to find the solution. I have come across a comment that says that the "frm_Main.Show()" call is "not persistent", but frankly this means little to me and searching for details regarding this comment is simply confusing.
I am pasting the code from the two forms below, any advice / help / assistance would be much appreciated:
frm_login code
VB.NET:
Imports MySql.Data.MySqlClient
Public Class frm_Login
Private Sub cmd_Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_Cancel.Click
Application.Exit()
End Sub
Public Sub cmd_Login_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_Login.Click
Dim conn = New MySqlConnection()
conn.ConnectionString = "server=localhost;user id=" & txt_User.Text & ";password=" & txt_Password.Text & ";database=db"
Try
conn.Open()
Me.Hide()
frm_Main.Show()
'MessageBox.Show("Connection Opened Successfully")
'conn.Close()
Catch myerror As MySqlException
MessageBox.Show("Error Connecting to Database: " & myerror.Message)
Finally
conn.close()
conn.Dispose()
Application.Exit()
End Try
End Sub
End Class
frm_Main code
VB.NET:
Public Class frm_Main
Private Sub frm_Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
I thought that once the control has been passed to frm_Main that the program should run in this class until the form control is closed?!?!?
Regards
Rob
Last edited by a moderator: