2、在工程文件中添加对以上二个dll文件的援用;
3、详细代码以下:
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; } }
运转结果:
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);
以上就是运用Visual Studio的动态衔接库建立通用数据库衔接对话框的内容,更多相关内容请关注ki4网(www.ki4.cn)!