using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace 测试2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//Data Source=L_RYAN-PC\SQLEXPRESS;Initial Catalog=test;Integrated Security=True
string ConnectionString = "SIMON-PC\\SQLEXPRESS\\SQLEXPRESS;Initial Catalog=Hospetal;Integrated Security=True";
using(SqlConnection conn = new SqlConnection())//创建连接对象
{
conn.ConnectionString = ConnectionString;//给连接对象的连接路径赋值
conn.Open();//运行连接对象,即是连接数据库
SqlCommand cmd = new SqlCommand();//创建命令对象
cmd.Connection = conn;//命令对象通过连接对象连接数据库发送命令
cmd.CommandText = "insert into 病人 values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "')";//命令对象发送命令的原文本
int i = cmd.ExecuteNonQuery();//运行命令对象
MessageBox.Show("插入成功!");
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
}
}
沧海一幻觉
相关分类