引用C:\Program Files\Microsoft Visual Studio 8\Common7\IDE 里面的Microsoft.Data.ConnectionUI.Dialog.dll。

using Microsoft.Data.ConnectionUI;

DataConnectionDialog dialog = new DataConnectionDialog();

            dialog.DataSources.Add(DataSource.SqlDataSource);
            dialog.SelectedDataProvider = DataProvider.SqlDataProvider;

            //dialog.DataSources.Add(DataSource.OdbcDataSource);

            //dialog.SelectedDataSource = DataSource.OdbcDataSource;
            //dialog.SelectedDataProvider = DataProvider.OdbcDataProvider;

            dialog.StartPosition = FormStartPosition.CenterScreen;
            dialog.Title = "Connect to SqlServer";
            dialog.ConnectionString = "server=127.0.0.1;database=YarnNew;user id=sa;password=aaa;";


            if (DataConnectionDialog.Show(dialog, this) == DialogResult.OK)
            {
                MessageBox.Show(dialog.ConnectionString);
            }

posted on 2008-02-01 16:00 lunar 阅读(...) 评论(...) 编辑 收藏