using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsFormsApplication54
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == string.Empty)
{
MessageBox.Show("请输入数据库名称");
}
else
{
try
{
string constr = "server=.;database=db_PWMS;Integrated Security=SSPI";
SqlConnection conn = new SqlConnection(constr);
conn.Open();
if (conn.State == ConnectionState.Open)
{
label1.Text = "数据库已经打开";
}
}
catch
{
MessageBox.Show("数据库连接失败");
}
}
}
}
}
这是程序