(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/webkaifa/)using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Data.ConnectionUI;
namespace ConnectionBuilder
{
public partial class ConnectionForm : Form
{
public ConnectionForm()
{
InitializeComponent();
}
private void btnCreateConnection(object sender, EventArgs e)
{
DataConnectionDialog dialog = new DataConnectionDialog();
//添加数据源列表,可以向窗口中添加自己程序所需要的数据源类型
dialog.DataSources.Add(DataSource.SqlDataSource);
dialog.DataSources.Add(DataSource.OdbcDataSource);
dialog.SelectedDataSource = DataSource.OdbcDataSource;
dialog.SelectedDataProvider = DataProvider.OdbcDataProvider;
//只能够通过DataConnectionDialog类的静态方法Show出对话框
//不同使用dialog.Show()或dialog.ShowDialog()来呈现对话框
if (DataConnectionDialog.Show(dialog, this) == DialogResult.OK)
{
txtConnectionString.Text = dialog.ConnectionString;
}
}
}
}