using System.Data.SqlClient;
namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
string connectionString="Server=(local);Integrated Security=SSPI;Database=student";
SqlConnection sqlCnn=new SqlConnection(connectionString);
sqlCnn.Open();
MessageBox.Show("连接成功!");
}
catch(SqlException ex)
{
MessageBox.Show(ex.Message);
}
}
}
}