Solved

Can't pass connection from one form to another

Posted on 2008-06-12
1
218 Views
Last Modified: 2013-11-26
Hi everyone,

I'm completely stuck at passing the connection info from my login form to my main form. The program should:

- Connect to the remote MySQL DB
- Fetch a list of usernames so the user select his/her
- Validate the user's password with the MD5 password stored in the DB
- If the user and password matches, show the main form
- Open the main form having the connection stablished (this is the problem)

I attached two TXT files with both forms to see if anyone can help me with this.

Thanks a lot in advanced!!
login.txt
main.txt
0
Comment
Question by:Caracena
1 Comment
 
LVL 9

Accepted Solution

by:
Rurne earned 500 total points
ID: 21771756
It looks like your MySQLConnection is simply falling out of scope.   In login.txt, you define

"Public Class frmLogin
    Dim conn As MySqlConnection
    Dim myCommand As New MySqlCommand
    Dim myAdapter As New MySqlDataAdapter"


conn, myCommand, and myAdapter are thus all local properties of the frmLogin class.  As you never pass it to frmMain before calling frmMain.Show(), calling conn.Open() and conn.Close() in frmMain_Load should result in error: frmMain.conn has no parameters, as it's a completely separate MySQLConnection from frmLogin.conn.

The easiest way around this would be to define conn, not as a property of either class, but as a global MySQLConnection, which you can then reference in the appropriate namespaces.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
Creating and Managing Databases with phpMyAdmin in cPanel.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question