1. Find Microsoft. Data.ConnectionUI.dll, Microsoft.Data.ConnectionUI.Dialog.dll and the Chinese resource file Microsoft.Data.ConnectionUI.Dialog.resources.dll. Note that the Chinese resource file needs to be placed in the zh-CHS folder;
##2. Add in the project file References to the above two dll files;
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;
}
}
Displayed when reopening, the previously selected 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;
//之前 DataConnectionDialog 控件保存的连接字符串
dialog.ConnectionString = str;
//ConnectionString有值,则会显示出来
DataConnectionDialog.Show(dialog, this);
The above is the content of using the dynamic link library of Visual Studio to create a universal database connection dialog box. For more related content, please pay attention to the PHP Chinese website ( m.sbmmt.com)!