vb.NET 2008: How to use a database connection through multiple forms
I'm testing databa开发者_运维技巧se programming in vb.NET 2008 at the moment and try to find a way to use a database connection in different forms, so e.g. I put the the database-connection-component into one of the forms.
I know, I could access it by e.g. form1.databaseconnection.xxx, but is this the best way or can I "put" the connection into something more abstract which all forms know about?
Thanks
Better if you implement a Data Access Layer on a separate Class Libraray project and add a reference to it on you windows application project.
I had to take a pretty similar design decision, and I decided that it would be the best to share the connection from one major object, and hand it to Forms by calling an overloaded Show()-Method.
Public Overloads Sub Show(ByVal mainController As MyController)
_handedController = mainController
End Sub
MyController is a class which holds several important things, like the DB-Connection etc. .
精彩评论