简体   繁体   English

usercontrol连接到SqlServer数据库

[英]usercontrol to connect to a SqlServer database

I've been writing some small maintenance/viewer tools that each connect to a SQLServer (2005) database via System.Data.SqlClient classes. 我一直在编写一些小的维护/查看器工具,每个工具都通过System.Data.SqlClient类连接到SQLServer(2005)数据库。 (C# - .NET 3.5 - Windows.Forms) (C#-.NET 3.5-Windows.Forms)

For each of these tools I had to write the UI and dialog to let the user choose the right db and server: I connect to my test-db, my colleague uses my tools too and connects his test-db. 对于这些工具,我必须编写UI和对话框,以便用户选择正确的数据库和服务器:我连接到test-db,同事也使用我的工具并连接他的test-db。

I'm looking for a plugable usercontrol that lets the user select a server, db and the rest of the connection parameters and that provides a SqlClient.SqlConnection to the rest of the application. 我正在寻找一个可插入的用户控件,该控件可让用户选择服务器,数据库和其余的连接参数,并为应用程序的其余部分提供SqlClient.SqlConnection。

I've tried writing a usercontrol myself now, but I'm sure there must be others ,better ones and better tested ones. 我现在尝试自己编写一个用户控件,但是我确信必须有其他,更好的和经过更好测试的控件。 I've been Googling and looking at CodeProject, but found none. 我一直在谷歌搜索并查看CodeProject,但没有发现。

There must be some better than one I wrote recently, because that one's so bad: 肯定有一些比我最近写的要好,因为那太糟糕了:

Just 只是

  1. Create a user control 创建一个用户控件
  2. drag a couple of buttons to it, anchor bottom center, make them ok and cancel 将几个按钮拖到其上,锚定底部中心,使其确定并取消
  3. drag a Property Grid control onto it, dock fill 将属性网格控件拖到其上,停靠填充
  4. Add a read-only property to the control of type SqlConnectionStringBuilder, back it with a field 向类型SqlConnectionStringBuilder的控件中添加一个只读属性,并使用一个字段将其备份
  5. Initialize the field to a new SqlConnectionStringBuilder instance 将字段初始化为新的SqlConnectionStringBuilder实例
  6. In the Load event, set the Object property of the property grid to the SqlConnectionStringBuilder 在Load事件中,将属性网格的Object属性设置为SqlConnectionStringBuilder

That's pretty much that. 差不多了。 The user just gets to fill in the properties. 用户只需填写属性即可。 If you like, you can also create a ConnectionString property on the control and have it return the .ConnectionString property of the SqlConnectionStringBuilder. 如果愿意,还可以在控件上创建ConnectionString属性,并使其返回SqlConnectionStringBuilder的.ConnectionString属性。

What you're describing here is simple enough that I doubt there's something out there that does only this. 什么你所描述这里是很简单的,我怀疑有东西在那里,确实只有这个。 You'd probably be better off sticking with your own code here. 您最好在这里坚持自己的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM