没什么实质意义的功能,就是生成连接SQL Server数据库时的字符串!
主要做法在窗体加载的时候将SqlConnectionStringBuilder的相关属性映射到PropertyGrid中(修改PropertyGrid中相关设置会影响SqlConnectionStringBuilder对象的值),点击按钮的时候,将生成的文本复制到粘贴板和TextBox中!
窗体控件名称啥的,相信壹看就懂!
直接上代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SQLConnectionStringBuilder
{
public partial class MainFrm : Form
{
public MainFrm()
{
InitializeComponent();
SqlConnectionStringBuilder scsb = new SqlConnectionStringBuilder();
this.propertyGrid4ConnectionString.SelectedObject = scsb;
}
private void btnGetString_Click(object sender, EventArgs e)
{
string str = this.propertyGrid4ConnectionString.SelectedObject.ToString();
Clipboard.Clear();
Clipboard.SetText(str);
MessageBox.Show("连接字符串已经复制到粘贴板:\n"+str);
tbString.Text = str;
}
}
}