1. In the VS (here Directory file takes vs2010 as an example) under the installation directory ("%visual Studio installation directory%/common10/ide/microsoft.data.connectionui.dialog.dll" ) Find Microsoft.Data.ConnectionUI.dll, Microsoft.Data.ConnectionUI.Dialog.dll and Chinese resources file Microsoft.Data.ConnectionUI.Dialog.resources.dll, note that the Chinese resources files need to be placed under the Zh-chs folder;
2. Add references to the above two DLL files in the project file;
3, the specific code is as follows:
private void Button1_Click (object sender, EventArgs e) { dataconnectiondialog dialog = new Dataconnectiondialog (); Dialog. Datasources.add (Datasource.accessdatasource); Dialog. Datasources.add (Datasource.odbcdatasource); Dialog. Datasources.add (Datasource.oracledatasource); Dialog. Datasources.add (Datasource.sqldatasource); Dialog. Datasources.add (Datasource.sqlfiledatasource); Dialog. Selecteddatasource = Datasource.sqldatasource; Dialog. Selecteddataprovider = Dataprovider.sqldataprovider; if (dataconnectiondialog.show (dialog, this) = = DialogResult.OK) { //conndlg.connectionstring; } }
Operating effect:
Show when re-open, before selecting the connection string:
Dataconnectiondialog dialog = new Dataconnectiondialog (); Dialog. Datasources.add (Datasource.accessdatasource); Dialog. Datasources.add (Datasource.odbcdatasource); Dialog. Datasources.add (Datasource.oracledatasource); Dialog. Datasources.add (Datasource.sqldatasource); Dialog. Datasources.add (Datasource.sqlfiledatasource); Dialog. Selecteddatasource = Datasource.sqldatasource; Dialog. Selecteddataprovider = Dataprovider.sqldataprovider; The connection string dialog previously saved by the Dataconnectiondialog control . ConnectionString = str; ConnectionString has a value, it will be displayed dataconnectiondialog.show (dialog, this);
The above is the content of creating a Common Database Connection dialog box using the Visual Studio Dynamic Connection library, and more about topic.alibabacloud.com (www.php.cn)!