现在的位置: 首页 > 综合 > 正文

直接调用内置数据源连接对话框(C#/VB.NET2005源码)

2013年09月10日 ⁄ 综合 ⁄ 共 1498字 ⁄ 字号 评论关闭

 '先引用Microsoft.Data.ConnectionUI.Dialog.dll(在VS2005安装路径的IDE目录下)
D:/Program Files/Microsoft Visual Studio 8/Common7/IDE
VB: 

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

C#2005

            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;

            string strCon = "";
            DataConnectionDialog.Show(dialog);
            if (dialog.DialogResult == DialogResult.OK)
            { strCon = dialog.ConnectionString; }
            else if (dialog.DialogResult == DialogResult.Cancel)
            { }

            MessageBox.Show(strCon);

抱歉!评论已关闭.