C# winform简易图书管理系统设计代码(只实现增删查改的操作) using System; using System.Data; using System.Windows.Forms; using System.Data.SqlClient; namespace librarian { public partial class Form1 : Form { public Form1() { InitializeComponent(); } //声明参数 string conStr; SqlConnection conn; //声明数据库连接方法体 private void DBConnect() { conStr = "server=localhost;database=DBbook;UID=sa;password=dataadmin"; conn = new SqlConnection(conStr); } //图书查找功能 private void butSelect_Click(object sender, EventArgs e) { DBConnect(); if (txtID.Text != "") { //用图书编号查找图书 string cmdStr = "select * from TbBookMessage where bookID='" + txtID.Text + "'"; SqlCommand cmd = new SqlCommand(cmdStr, conn); SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = cmd; //将sql执行语句设置为已实例化的SqlDataAdapter查询命令 DataSet ds = new DataSet(); da.Fill(ds); //把数据填充到"临时仓库"DataSet if (ds.Tables[0].Rows.Count > 0) { // 临时仓库表中存在数据时,将对应字段填充到textbox中 txtID.Text = ds.Tables[0].Rows[0]["bookID"].ToString(); txtName.Text = ds.Tables[0].Rows[0]["bookName"].ToString(); txtMessage.Text = ds.Tables[0].Rows[0]["bookMessage"].ToString(); } else { MessageBox.Show("您要找的图书不存在或已删除", "提示"); txtID.Clear(); //清空txtID文本框 txtID.Focus(); //设为焦点 } } else if (txtID.Text == "" && txtName.Text != "") { //用图书名称查找图书 string cmdStr = "select * from TbBookMessage where bookName='" + txtName.Text + "'"; SqlCommand cmd = new SqlCommand(cmdStr, conn); SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = cmd; DataSet ds = new DataSet(); da.Fill(ds); if (ds.Tables[0].Rows.Count > 0) { txtID.Text = ds.Tables[0].Rows[0]["bookID"].ToString(); txtName.Text = ds.Tables[0].Rows[0]["bookName"].ToString(); txtMessage.Text = ds.Tables[0].Rows[0]["bookMessage"].ToStr...