Click here to Skip to main content
15,915,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to use the connection objects declred in on win form to another win form
Posted

you can declare them as public or as a property
 
Share this answer
 
Comments
[no name] 22-Nov-11 4:37am    
how it is possible.i tried but not working
for example

C#
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    public object C1
    {
        get;
        private set;
    }
}
 
Share this answer
 
Form1
-----------

Define Connection object as objConnection in the First Form.
Add a button and Write the code on the Button Click Event.

SqlConnection objCon=new SqlConnection(//Define credentials);
Form2 objfomr2=new Form2(objCon);
objfomr2.Show();

Form2
-------------
Define the parameterised constructor and get the value of the same connection object as below.
Declare a connection reference object as conref.

SqlConnection con;
public Form2(SqlConnection con)
{
InitializeComponent();
this.conref= con;
}

This Connection object conref has the same value as in Form1.
 
Share this answer
 
Passing Data Between Forms

Hope this article will helps
 
Share this answer
 

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