how to pass connection

  • Thread starter Thread starter drama
  • Start date Start date
D

drama

information from form1 to form2 one time in holle project

form exitample
-------------
public partial class Form1 : Form
{ public Form2 f2 = new Form2();
public Form1 f1 = new Form1();
string st = "server=localhost;user id=root; password=;
database=nwin; pooling=false";

public MySqlConnection conn = new MySqlConnection();
conn.connectionString=st;
conn.open( ); // connection is opening now
..
..
..
-.*----
- ----
------now FORM2
public partial class Form2 : Form

hot to get that "conn" from form1
 
Why do you need to keep the connection info in presentation level (Forms)?

The best way is to allocate any DAL information in a separated class and
extract any data from here. The form should not need to know anything about
it. So, keep your connection string in config file and make your forms received
info from some DAL-class, which incapsulate all work with DB layer.

ps. also don't pass the openned connection. you should open and close connection
asap. the data layer always have limited connections.

Alex
http://devkids.blogspot.com
 
Back
Top