用户控件连接到SQLServer数据库 [英] usercontrol to connect to a SqlServer database
问题描述
我一直在写一些小的维修/浏览器工具,每一个连接到通过System.Data.SqlClient的班一个SQLServer(2005)数据库。
(C# - .NET 3.5 - Windows.Forms的)
I've been writing some small maintenance/viewer tools that each connect to a SQLServer (2005) database via System.Data.SqlClient classes. (C# - .NET 3.5 - Windows.Forms)
有关这些工具我不得不写UI和对话框让用户选择权数据库和服务器:我连接到我的测试分贝,我的同事使用我的工具也和他的连接测试,分贝
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.
我在寻找一个可插拔的用户控件,让用户选择服务器,数据库和连接参数的其余部分,它提供了一个SqlClient.SqlConnection到应用程序的其余部分。
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.
我试图写一个用户控件现在我自己,但我敢肯定,必须有其他更好的和更好的测试的。我一直在谷歌上搜索和寻找在CodeProject,但是毫无结果。
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.
推荐答案
有一定有不止一个我最近写的好,因为,一个人的如此糟糕:
There must be some better than one I wrote recently, because that one's so bad:
只是
- 创建一个用户控件
- 将几个按钮吧,锚底部中间,让他们确定和取消
- 将属性网格控制到它,码头填充
- 一个只读属性添加到类型SqlConnectionStringBuilder的控制,后其与字段
- 字段初始化到一个新的SqlConnectionStringBuilder实例
- 在Load事件,属性网格的对象属性设置为SqlConnectionStringBuilder
- Create a user control
- drag a couple of buttons to it, anchor bottom center, make them ok and cancel
- drag a Property Grid control onto it, dock fill
- Add a read-only property to the control of type SqlConnectionStringBuilder, back it with a field
- Initialize the field to a new SqlConnectionStringBuilder instance
- In the Load event, set the Object property of the property grid to the SqlConnectionStringBuilder
这是相当多的。用户只需得到填补的属性。如果你喜欢,你还可以在控制创建ConnectionString属性,并将其返回SqlConnectionStringBuilder的.ConnectionString属性。
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.
这篇关于用户控件连接到SQLServer数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!