C#代码 数据库连接配置界面

以前做Winform程序,居然专门做一个界面来配置连接字符串。今天无意中发现:竟然可以直接调用VS.net2005中的配置界面来处理。 使用方法也及其简便: 一、添加引用 C:/Program Files/Microsoft Visual Studio 8/Common7/IDE/Microsoft.Data.ConnectionUI.Dialog.dll 二、引入名称空间 C# code using Microsoft.Data.ConnectionUI; 三、代码 C# code DataConnectionDialog dlg = new DataConnectionDialog(); dlg.DataSources.Add(DataSource.SqlDataSource); dlg.SelectedDataProvider = DataProvider.SqlDataProvider; DataConnectionDialog.Show(dlg, this); 比如说放在一个按钮的Click事件里 C# code private void button1_Click(object sender, EventArgs e) { DataConnectionDialog dlg = new DataConnectionDialog(); dlg.DataSources.Add(DataSource.SqlDataSource); dlg.SelectedDataProvider = DataProvider.SqlDataProvider; DataConnectionDialog.Show(dlg, this); } 四、运行 界面出来了,是不是相当的专业! DataConnectionDialog 还有很多属性,配置这些属性可以改变窗口外观,满足不同需求。
posted @ 2010-10-07 18:29  deepwishly  阅读(333)  评论(0编辑  收藏  举报