how to pass connection

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
 
A

Alex Meleta

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top