vb.NET 2008:如何通过多种形式使用数据库连接

发布于 2024-08-23 10:36:49 字数 183 浏览 1 评论 0原文

我目前正在 vb.NET 2008 中测试数据库编程,并尝试找到一种以不同形式使用数据库连接的方法,因此,例如,我将数据库连接组件放入其中一个形式中。

我知道,我可以通过例如 form1.databaseconnection.xxx 访问它,但这是最好的方法还是我可以将连接“放入”所有表单都知道的更抽象的东西中?

谢谢

I'm testing database 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

星星的轨迹 2024-08-30 10:36:49

如果您在单独的类库项目上实现数据访问层并在 Windows 应用程序项目上添加对它的引用,那就更好了。

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.

笨死的猪 2024-08-30 10:36:49

我必须做出一个非常相似的设计决策,并且我决定最好共享一个主要对象的连接,并通过调用重载的 Show() 方法将其传递给 Forms。

Public Overloads Sub Show(ByVal mainController As MyController)
    _handedController = mainController
End Sub

MyController 是一个包含几个重要内容的类,例如 DB-Connection 等。

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. .

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文