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=Truestring 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){}}}
1 回答
沧海一幻觉
TA贡献1824条经验 获得超5个赞
string ConnectionString = "server=SIMON-PC\\SQLEXPRESS\\SQLEXPRESS;Initial Catalog=Hospetal;Integrated Security=True";
添加回答
举报
0/150
提交
取消