Click here to Skip to main content
15,920,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Okay this is my connection code


C#
class myConnection
{
    public static string datasource = "";
    public static string initialcatalog = "";
    public static string uid = "";
    public static string pwd = "";
    public static MySqlConnection GetConnection()
    {
        string str = "SERVER='" + datasource + "';DATABASE='" + initialcatalog + "';UID='" + uid + "';PASSWORD='" + pwd + "'";
        MySqlConnection con = new MySqlConnection(str);
        con.Open();
        return con;
    }
}



i cant seem to figure out how to make it Show form2 if it actually connects to the database, i have done this befor but im completely drawing a blank in my mind and i cant find anything on google (i suck at searching lol)

Any help would be apreciated
Posted

1 solution

Assuming Form2 is the form you wish to show and you are in Form1, you could do this:

public partial class Form1 : Form
{
...
public void ShowForm2()
{
    MySqlConnection connection = myConnection.GetConnection();

    if (connection != null)
    {
         Form2 frm2 = new Form2();
         frm2.Show();
         // or 
         // frm2.ShowDialog();
    }
}
...
}


Note - I am assuming you haven't posted all of your "myConnection" class and so didn't verify that. But this is how you show another form to the user
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900