使用VS的动态连接库创建通用数据库连接对话框
时间:2011-05-04 来源:姚箫
1、在VS安装目录下找到Microsoft.Data.ConnectionUI.dll、Microsoft.Data.ConnectionUI.Dialog.dll和汉化资源文件Microsoft.Data.ConnectionUI.Dialog.resources.dll,注意汉化资源文件需要放在zh-CHS文件夹下;
2、在工程文件中添加对以上二个dll文件的引用;
3、编写运行代码:
1 private void button1_Click(object sender, EventArgs e)
2 {
3 DataConnectionDialog connDlg = new DataConnectionDialog();
4 connDlg.DataSources.Add(DataSource.AccessDataSource);
5 connDlg.DataSources.Add(DataSource.OdbcDataSource);
6 connDlg.DataSources.Add(DataSource.OracleDataSource);
7 connDlg.DataSources.Add(DataSource.SqlDataSource);
8 connDlg.DataSources.Add(DataSource.SqlFileDataSource);
9
10 connDlg.SelectedDataSource = DataSource.SqlDataSource;
11 connDlg.SelectedDataProvider = DataProvider.SqlDataProvider;
12
13 if (DataConnectionDialog.Show(connDlg, this) == DialogResult.OK)
14 {
15 this.textBox1.Text = connDlg.ConnectionString;
16 }
2 {
3 DataConnectionDialog connDlg = new DataConnectionDialog();
4 connDlg.DataSources.Add(DataSource.AccessDataSource);
5 connDlg.DataSources.Add(DataSource.OdbcDataSource);
6 connDlg.DataSources.Add(DataSource.OracleDataSource);
7 connDlg.DataSources.Add(DataSource.SqlDataSource);
8 connDlg.DataSources.Add(DataSource.SqlFileDataSource);
9
10 connDlg.SelectedDataSource = DataSource.SqlDataSource;
11 connDlg.SelectedDataProvider = DataProvider.SqlDataProvider;
12
13 if (DataConnectionDialog.Show(connDlg, this) == DialogResult.OK)
14 {
15 this.textBox1.Text = connDlg.ConnectionString;
16 }
17 }
4、效果图如下:
相关阅读 更多 +