Solved

Can't pass connection from one form to another

Posted on 2008-06-12
1
216 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

760 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now