Home  >  Article  >  Backend Development  >  Create a universal database connection dialog box using Visual Studio's dynamic link library

Create a universal database connection dialog box using Visual Studio's dynamic link library

黄舟
黄舟Original
2017-02-15 11:41:571708browse

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;
            }
        }
Run Effect:


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 ( www.php.cn)!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn