资产负债率下降说明:直接调用内置数据源连接对话框(C#/VB.NET2005源码) - 瘦山鸿的I.T.生活 - 博客园

来源:百度文库 编辑:九乡新闻网 时间:2024/05/03 03:49:03

'先引用Microsoft.Data.ConnectionUI.Dialog.dll(在VS2005安装路径的IDE目录下)
'将以下代码加入相应事件过程  
                 Dim dialog As DataConnectionDialog = New DataConnectionDialog()
                    dialog.DataSources.Add(DataSource.SqlDataSource)
                    dialog.DataSources.Add(DataSource.OdbcDataSource)
                    dialog.DataSources.Add(DataSource.OracleDataSource)
                    dialog.DataSources.Add(DataSource.AccessDataSource)

                    dialog.SelectedDataSource = DataSource.SqlDataSource
                    dialog.SelectedDataProvider = DataProvider.SqlDataProvider

                        DataConnectionDialog.Show(dialog)
                    If dialog.DialogResult = Windows.Forms.DialogResult.OK Then
                        Me.TextBox1.Text = dialog.ConnectionString
                    ElseIf dialog.DialogResult = Windows.Forms.DialogResult.Cancel Then
                        Me.Close()
                    End If

谢谢 Tonyyang 转为C#,在此一并归纳,但此C#代码我没有测试过,请发现问题的同行指正:
 C#2005 Code

DataConnectionDialog dialog = new DataConnectionDialog();
dialog.DataSources.Add(DataSource.SqlDataSource);
dialog.DataSources.Add(DataSource.OdbcDataSource);
dialog.DataSources.Add(DataSource.OracleDataSource);
dialog.DataSources.Add(DataSource.AccessDataSource);

dialog.SelectedDataSource = DataSource.SqlDataSource;
dialog.SelectedDataProvider = DataProvider.SqlDataProvider;

DataConnectionDialog.Show(dialog);
if (dialog.DialogResult == DialogResult.OK)
{ textBox1.Text = dialog.ConnectionString; }
else if (dialog.DialogResult == DialogResult.Cancel)
{ }
//Me.Close();