⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form3.cs

📁 用Csharp编写的一个图书馆里系统
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsApplication1
{
    public partial class Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string str1 = this.textBox7.Text.Trim();
            string str2 = this.textBox5.Text.Trim();
            string str3 = this.textBox2.Text.Trim();
            string str4 = this.textBox1.Text.Trim();
            string str5 = this.textBox3.Text.Trim();
            string str6 = this.textBox4.Text.Trim();
            string str7 = this.textBox6.Text.Trim();
            SqlConnection conn = new SqlConnection(@"Data Source=.;Initial Catalog=tushu; Integrated Security=True");
            try
            {
                conn.Open();
                string sql = @"insert into booktable
                              values(@bookno,@barcode,@bookna,@auther,@authorna,@price,@bookcase)";
                SqlCommand cmmd = new SqlCommand(sql, conn);
                SqlParameter pbookno = new SqlParameter("@bookno", SqlDbType.VarChar);
                SqlParameter pbarcode = new SqlParameter("@barcode", SqlDbType.Char);
                SqlParameter pbookna = new SqlParameter("@bookna", SqlDbType.VarChar);
                SqlParameter pauther = new SqlParameter("@auther", SqlDbType.VarChar);
                SqlParameter pauthorna = new SqlParameter("@authorna", SqlDbType.VarChar);
                SqlParameter pprice = new SqlParameter("@price", SqlDbType.VarChar);
                SqlParameter pbookcase = new SqlParameter("@bookcase", SqlDbType.VarChar);
                pbookno.Value = str1;
                pbarcode.Value = str2;
                pbookna.Value = str3;
                pauther.Value = str4;
                pauthorna.Value = str5;
                pprice.Value = str6;
                pbookcase.Value = str7;
                cmmd.Parameters.Add(pbookno);
                cmmd.Parameters.Add(pbarcode);
                cmmd.Parameters.Add(pbookna);
                cmmd.Parameters.Add(pauther);
                cmmd.Parameters.Add(pauthorna);
                cmmd.Parameters.Add(pprice);
                cmmd.Parameters.Add(pbookcase);
                if (cmmd.ExecuteNonQuery() == 1)
                {
                    MessageBox.Show("增加图书成功!");
                }
                else
                {
                    MessageBox.Show("增加图书失败!");
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message);
            }
            finally
            {
                conn.Close();
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -