一、添加引用
C:Program FilesMicrosoft Visual Studio 8Common7IDEMicrosoft.Data.ConnectionUI.Dialog.dll
二、引入名称空间
using Microsoft.Data.ConnectionUI;
三、代码
private void buttonConn_Click(object sender, EventArgs e) { DataConnectionDialog dialog = new DataConnectionDialog(); //添加数据源列表,可以向窗口中添加自己程序所需要的数据源类型 dialog.DataSources.Add(DataSource.SqlDataSource); dialog.DataSources.Add(DataSource.OdbcDataSource); dialog.SelectedDataSource = DataSource.SqlDataSource; dialog.SelectedDataProvider = DataProvider.SqlDataProvider; //只能够通过DataConnectionDialog类的静态方法Show出对话框 //不同使用dialog.Show()或dialog.ShowDialog()来呈现对话框 if (DataConnectionDialog.Show(dialog, this) == DialogResult.OK) { txtConnectionString.Text = dialog.ConnectionString; } }
四、运行界面