一、添加引用
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 ); }
四、运行