C#实现简单学生信息管理系统 情商书籍

C#实现简单学生信息管理系统 情商书籍

一、运行环境windows,使用vs编译软件二、主要功能登录、添加学生信息、修改学生信息、删除学生信息、查询学生信息三、实现步骤老规矩,先贴下主要代码://构造方法publicLogin(){InitializeComponent();=this;=;=;=;=;}//对登录按钮的事件实现代码privatevoidbutton1_Click(objectsender,EventArgse){stringss=["Stu"].ToString();SqlConnectionconn=newSqlConnection(ss);try{//开启连接();//("数据库连接成功!");}catch(Exception){//("数据库连接失败!");}Stringuname=();stringpword=();if(uname==""||pword==""){("请输入用户名或密码!");return;}else{SqlCommandcmd=();SqlDataAdapteradp=newSqlDataAdapter();stringsql2="select*fromaccountwherename="+uname+"andpass="+pword+"";=sql2;=cmd;DataSetdat=newDataSet();(dat,"account");if(["account"].==0){("用户名或密码错误!");return;}else{=true;=;();}();}();}//实现按ESC键关闭该窗口protectedoverrideboolProcessCmdKey(,){switch(keyData){:();//esc关闭窗体break;}returnfalse;}//重置按钮清空文本框privatevoidbutton2_Click(objectsender,EventArgse){="";="";}//密码输入完成后实现敲击enter键触发登录按钮privatevoidtxtPass_KeyDown(objectsender,KeyEventArgse){if(==){_Click(sender,e);}}//实现按enter键使焦点转移到下一文本框,与tab键通用privatevoidtxtName_KeyPress(objectsender,KeyPressEventArgse){if(==(char)){("{tab}");}}效果如下图:主要代码如下:publicstaticboolisLogin=false;intid;SqlConnectionconn;SqlCommandcmd;SqlDataAdapteradp;DataSetdat;publicstaticstringusername{get;set;}publicForm1(){InitializeComponent();=;=;=;=;=;=;+="|管理员:"+username;stringss=["Stu"].ToString();//建立数据库连接conn=newSqlConnection(ss);try{//开启连接();//("数据库连接成功!");}catch(Exception){("数据库连接失败!");}}privatevoidForm1_Load(objectsender,EventArgse){DataGridViewDataLoad();//_(_dent);}privatevoidDataGridViewDataLoad(){Stringsql1="select*fromStu_dent";adp=newSqlDataAdapter(sql1,conn);dat=newDataSet();(dat);=[0];}privatevoidbutton5_Click(objectsender,EventArgse){stringnum=();stringname=();Stringsql4="Select*fromStu_dentwhere1=1";if(!(num)){sql4+="andStuNum="+num;}if(!(name)){sql4+="andStuNamelike%"+name+"%";}adp=newSqlDataAdapter(sql4,conn);dat=newDataSet();(dat);=[0];}protectedoverrideboolProcessCmdKey(,){switch(keyData){:();//esc关闭窗体break;}returnfalse;}privatevoidbutton1_Click(objectsender,EventArgse){AddStudentaddStudent=newAddStudent();=;//();();DataGridViewDataLoad();}privatevoidbutton4_Click(objectsender,EventArgse){();}privatevoidbutton2_Click(objectsender,EventArgse){("请在学生信息显示框中双击所要删除学生所在的那一行即可!!!","提示");}privatevoidbutton3_Click(objectsender,EventArgse){("请在学生信息显示框中单击所要删修改学生所在的那一行的任意文字区域即可!","提示");}privatevoiddataGridView1_CellDoubleClick(objectsender,DataGridViewCellEventArgse){DialogResultresult=("确定删除该学生信息?","删除",);if(result==){id=([].Cells[0].Value);(id);stringsql2="deletefromStu_dentwhereID="+id;cmd=newSqlCommand(sql2,conn);();}DataGridViewDataLoad();}privatevoiddataGridView1_CellContentClick(objectsender,DataGridViewCellEventArgse){id=([].Cells[0].Value);UpdateStudentupdatestudent=newUpdateStudent(id);=;();DataGridViewDataLoad();}。