封装 SqlConnection,定义成Static ,或者用singleton
public class CustomisedConnection
{
public static CustomisedConnection ConnectionInstance = new CustomisedConnection();
SqlConnection _conn;
private CustomisedConnection(){_conn = new SqlConnection();}
}
调用CustomisedConnection.ConnectionInstance 就好了
把你的连接对象做成全局变量
写个数据库连接的类返回个sqlconnection对象就是了,每个窗口调用吧
做一个数据连接层(三层结构听说过吧?),数据处理跟界面分开。