基本信息
源码名称:C# 数据库增删改查-入门级示例(含数据库脚本)
源码大小:8.82M
文件格式:.zip
开发语言:C#
更新时间:2019-06-22
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍

建立一个简单的学生信息管理系统实行简单的数据库增删改查(含数据库)

【调试说明】

通过SQLQuery1.sql 创建sql server数据库,无须修改数据库连接串 即可运行程序

账号密码均为 admin








using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace 学生管理系统
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void Button1_Click(object sender, EventArgs e)
        {
            //判断用户名和密码
            String name = textBox1.Text.Trim();
            String pwd = textBox2.Text.Trim();
            if (String.IsNullOrEmpty(name) || String.IsNullOrEmpty(pwd))
            {
                MessageBox.Show("用户名或密码不能为空!");
                return;
            }
            //数据库链接
            String mycon = "Data Source=.;Initial Catalog=userDB;Integrated Security=True";
            SqlConnection con = new SqlConnection(mycon);
            con.Open();
            if (con.State!=ConnectionState.Open)
            {
                MessageBox.Show("链接数据库失败");
                return;
            }
            String sql = string.Format("select count(*) from T_user where username = '{0}'and userpwd='{1}'", name, pwd);
            SqlCommand cmd = new SqlCommand(sql, con);
            int i = Convert.ToInt32(cmd.ExecuteScalar());
            if (i > 0)//如果大于1,说明记录存在,登录成功
            {
                MessageBox.Show("登录成功!");
                this.DialogResult = DialogResult.OK;
                con.Close();
                this.Dispose();
                this.Close();
            }
            else
            {
                MessageBox.Show("用户名或者密码错误!");
            }
            
        }
        private void Button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        //点击控件窗口最小化
        private void Label3_Click(object sender, EventArgs e)
        {
            WindowState = FormWindowState.Minimized;
        }
        //鼠标移动到控件时背景颜色发生变化以及字体颜色变成白色
        private void Label3_MouseMove(object sender, MouseEventArgs e)
        {
            label3.ForeColor = Color.White;
            label3.BackColor = Color.FromArgb(30, 0, 0, 0);
        }
        //鼠标离开最小化控件时字体颜色以及背景颜色恢复原样
        private void Label3_MouseLeave(object sender, EventArgs e)
        {
            label3.ForeColor = Color.DimGray;
            label3.BackColor = Color.Transparent;
        }
        //点击控件关闭窗口
        private void Label4_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        //鼠标移动到控件时背景颜色变成红色
        private void Label4_MouseMove(object sender, MouseEventArgs e)
        {
            label4.BackColor = Color.Red;
        }
        //鼠标移动到控件时背景颜色变成透明
        private void Label4_MouseLeave(object sender, EventArgs e)
        {
            label4.BackColor = Color.Transparent;
        }
        private Point mPoint;
        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            mPoint = new Point(e.X, e.Y);
        }
        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                this.Location = new Point(this.Location.X   e.X - mPoint.X, this.Location.Y   e.Y - mPoint.Y);
            }
        }
    }
}