宿舍系统增加学生信息

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 DormManageSystem
{
    public partial class AddAccident : Form
    {
        private SqlConnection sqlConnection1 = null;
        public AddAccident()
        {
            InitializeComponent();
            this.sqlConnection1 = new SqlConnection(DormManageSystem.database.sqlConnection.connection);
        }

        private void btchongzhi_Click(object sender, EventArgs e)
        {
            dormid.Text = "";
            person.Text = "";
            koufen.Text = "";
            shijian.Text = "";
            chuli.Text = "";
        }

        private void btok_Click(object sender, EventArgs e)
        {
            try
            {
                if (dormid.Text.Trim() == "" || shijian.Text == ""||chuli.Text=="")
                    MessageBox.Show("请输入完整信息!", "提示");
                else
                {
                    sqlConnection1.Open();
                    string sql = "select * from dorm where dormid ='" + dormid.Text.Trim() + "'";
                    SqlCommand cmd = new SqlCommand(sql, sqlConnection1);
                    if (null == cmd.ExecuteScalar())
                        MessageBox.Show("没有该宿舍号,请重新输入!", "提示");
                    else
                    {
                        sql = "insert into accident(dormid,person,time,accident,koufen,deal) values('" + dormid.Text.Trim() + "','" + person.Text.Trim()+ "','" + date.Value.Date.ToString() + "','" + shijian.Text+ "','" + koufen.Text.Trim()+ "','" + chuli.Text + "')";
                        cmd.CommandText = sql;
                        cmd.ExecuteNonQuery();
                        MessageBox.Show("添加信息成功!", "提示");
                    }
                    sqlConnection1.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }


    }
}


上一篇:将列表转换成字符串


下一篇:StringUtils类isEmpty()、isBlank()、isAnyEmpty() 等判空方法总结,以及trim()字符串去空格