using System.Data.SqlClient;
namespace WindowsFormsApplication7
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string Sql;
string ConnectionString = "Server=(local);Integrated Security=SSPI;Database=student";
SqlConnection conn = new SqlConnection(ConnectionString);
conn.Open();
MessageBox.Show("连接成功!");
Sql="Select * from 学生";
try
{
SqlDataAdapter adapter = new SqlDataAdapter(Sql, conn);
DataTable datatable = new DataTable();
adapter.Fill(datatable);
Sql = "Insert Into 学生" + "Values('05','熊大','男','1995-5-12','2015-9-1','001')";
SqlCommand cmd = new SqlCommand();
cmd = new SqlCommand(Sql, conn);
MessageBox.Show("添加成功");
dataGridView1.DataSource = datatable;
}
catch (SqlException ex)
{
throw ex;
}
}
}
}