1、在VS(此處目錄檔案以vs2010為例)安裝目錄下(“%Visual Studio安裝目錄%/Common10/IDE/Microsoft.Data.ConnectionUI.Dialog.dll”)找到Microsoft.Data.ConnectionUI.dll、Microsoft.Data.ConnectionUI.Dialog.dll和漢化資源檔Microsoft.Data.ConnectionUI.Dialog.resources.dll,注意漢化資源檔需要放在zh-CHS檔案夾下;
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的動態串連庫建立通用資料庫連接對話方塊的內容,更多相關內容請關注topic.alibabacloud.com(www.php.cn)!