直接调用内置数据源连接对话框(VB.NET2005源码)
'先引用Microsoft.Data.ConnectionUI.Dialog.dll(在VS2005安装路径的IDE目录下)
'将以下代码加入相应事件过程
'将以下代码加入相应事件过程
1Dim dialog As DataConnectionDialog = New DataConnectionDialog()
2 dialog.DataSources.Add(DataSource.SqlDataSource)
3 dialog.DataSources.Add(DataSource.OdbcDataSource)
4 dialog.DataSources.Add(DataSource.OracleDataSource)
5 dialog.DataSources.Add(DataSource.AccessDataSource)
6
7 dialog.SelectedDataSource = DataSource.SqlDataSource
8 dialog.SelectedDataProvider = DataProvider.SqlDataProvider
9
10 DataConnectionDialog.Show(dialog)
11 If dialog.DialogResult = Windows.Forms.DialogResult.OK Then
12 Me.TextBox1.Text = dialog.ConnectionString
13 ElseIf dialog.DialogResult = Windows.Forms.DialogResult.Cancel Then
14 Me.Close()
15 End If
16
17
2 dialog.DataSources.Add(DataSource.SqlDataSource)
3 dialog.DataSources.Add(DataSource.OdbcDataSource)
4 dialog.DataSources.Add(DataSource.OracleDataSource)
5 dialog.DataSources.Add(DataSource.AccessDataSource)
6
7 dialog.SelectedDataSource = DataSource.SqlDataSource
8 dialog.SelectedDataProvider = DataProvider.SqlDataProvider
9
10 DataConnectionDialog.Show(dialog)
11 If dialog.DialogResult = Windows.Forms.DialogResult.OK Then
12 Me.TextBox1.Text = dialog.ConnectionString
13 ElseIf dialog.DialogResult = Windows.Forms.DialogResult.Cancel Then
14 Me.Close()
15 End If
16
17