Home > Backend Development > C#.Net Tutorial > 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

黄舟
Release: 2017-02-15 11:41:57
Original
1745 people have browsed it

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;
            }
        }
Copy after login
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);
Copy after login


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)!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template