//熊宇杰 20200933 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace tushuguanli { public partial class tianjiatushu : Form { public tianjiatushu() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } //创建数据库连接 private void button1_Click(object sender, EventArgs e) { //连接数据库 string str = @"Data Source=LAPTOP-HKE14BIG;Initial catalog=BookDB;integrated Security=True"; SqlConnection conn = new SqlConnection(str); conn.Open(); //分别插入书号、书名、书作者、出版社、数量 string selectsql = "insert into t_book values('" + textBox_Bid.Text + "','" + textBox_Bname.Text + "','" + textBox_Bauthor.Text + "','" + textBox_Bpress.Text +"','" + textBox_Bnu.Text + "')"; SqlCommand cmd = new SqlCommand(selectsql, conn); cmd.CommandType = CommandType.Text; SqlDataReader sdr; sdr = cmd.ExecuteReader(); conn.Close(); MessageBox.Show("添加成功!", "添加图书", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } ////////////////////////////////// /// //添加书号 private void label_Bid_Click(object sender, EventArgs e) { //书号标签:label_Bid } private void textBox_Bid_TextChanged(object sender, EventArgs e) { //文本按钮命名:textBox_Bid } //添加书名 private void label_Bname_Click(object sender, EventArgs e) { //书名标签:label_Bname } private void textBox_Bname_TextChanged(object sender, EventArgs e) { //文本按钮命名:textBox_Bname } //添加作者 private void label_Bauthor_Click(object sender, EventArgs e) { //书号标签:label_Bauthor } private void textBox_Bauthor_TextChanged(object sender, EventArgs e) { //文本按钮命名:textBox_Bautho } //添加出版社 private void label_Bpress_Click(object sender, EventArgs e) { //书号标签:label_Bpress } private void textBox_Bpress_TextChanged(object sender, EventArgs e) { //文本按钮命名:textBox_Bpress } //添加数量 private void label_Bnu_Click(object sender, EventArgs e) { //数量标签:label_Bnu } private void textBox_Bnu_TextChanged(object sender, EventArgs e) { //文本按钮命名:textBox_Bnu } } }