Solved

Can't pass connection from one form to another

Posted on 2008-06-12
1
220 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:Cesar Aracena
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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

730 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