ASP.NET实现学生管理系统
程序员文章站
2023-12-21 09:41:34
学生管理系统所需要的具体控件和主要属性:
1、登录窗体
基本控件:
label(标签控件)
主要属性:image(在标签上显示的图像)
text(在标签上显示的文...
学生管理系统所需要的具体控件和主要属性:
1、登录窗体
基本控件:
label(标签控件)
主要属性:image(在标签上显示的图像)
text(在标签上显示的文本)
textbox(文本框控件)
主要属性:passwordchar(指示在作为密码框时,文本框中显示的字符,而不是实际输入的文本)
button(按钮控件)
combobox(下拉框)属性:selecteditem:获取当前选定的项
事件:click(单击控件时发生)
private void butstyle_click(object sender, eventargs e) { string str = "data source=.;initial catalog=myschool;uid=sa"; sqlconnection con = new sqlconnection(str); string sql = "select count(1) from student where studentname='" + txtusername.text + "' and loginpwd='" + txtpwd.text + "'"; sqlcommand cmd = new sqlcommand(sql, con); try { con.open(); int count = convert.toint32(cmd.executescalar()); if (count > 0) { messagebox.show("登陆成功"); this.hide(); formmain frm = new formmain(); frm.show(); } } catch (exception) { messagebox.show("退出"); } finally { con.close(); }
sender是事件源,表示发生了这个事件的对象,事件发生中,事件源就是按钮。
e是事件参数(eventargs)对象,不同的事件会有不同的参数。
close()方法是窗体类form的一个方法,作用是关闭窗体。
2.myschool管理员
01.给菜单栏中的“新增学生”菜单项添加事件处理程序,代码如下
private void 新增学生toolstripmenuitem_click(object sender, eventargs e) { formstudent formstudent = new formstudent(); formstudent.show(); }
02.添加学生信息
public void save() { //添加学生 string pwd = txtpwd.text; string stuname = textname.text; //性别 string stugender = string.empty; if (radioman.checked) { stugender = "1"; } else { stugender = "0"; } //下拉框绑定数据 int gid = geadidname(); //联系电话 string stuphone = textphone.text; //地址 string stuaddress = textaddress.text; //日期 datetime dt = datebirthday.value; //邮箱 string stuemail = textemail.text; //loginpwd, studentname, gender, gradeid, phone, address, birthday, email string sql = "insert into student values('" + pwd + "','" + stuname + "','" + stugender + "'," + gid + ",'" + stuphone + "','" + stuaddress + "','" + dt + "','" + stuemail + "')"; string str = "data source=.;initial catalog=myschool;uid=sa;"; sqlconnection con = new sqlconnection(str); sqlcommand cmd = new sqlcommand(sql, con); con.open(); int count = cmd.executenonquery(); if (count > 0) { messagebox.show("添加成功"); } con.close(); }
3.查询学生信息
//查询学生信息
public void lodadatalistview(string sql) { string str = "data source=.;initial catalog=myschool;uid=sa;"; sqlconnection con = new sqlconnection(str); sqlcommand cmd = new sqlcommand(sql, con); try { con.open(); sqldatareader dr = cmd.executereader(); if (dr != null) { if (dr.hasrows) { while (dr.read()) { int stuno = convert.toint32(dr["studentno"]); //姓名 string stuname = convert.tostring(dr["studentname"]); //性别 string stugender = convert.tostring(dr["gender"]); //年级名次 string stugname = convert.tostring(dr["gradename"]); listviewitem lvitem = new listviewitem(stuno.tostring()); lvitem.subitems.add(stuname); lvitem.subitems.add(stugender); lvitem.subitems.add(stugname); //让lvitem和listview关联 lvlist.items.add(lvitem); } dr.close(); } } } catch (exception) { throw; } finally { con.close(); } //窗体load的事件中调用 private void formselect_load(object sender, eventargs e) { string sql = "select studentno,studentname,gender,gradename from student,grade where student.gradeid=grade.gradeid"; lodadatalistview(sql); }
修改学生信息
public void upatae() { //添加学生 string pwd = txtpwd.text; string stuname = textname.text; //性别 string stugender = string.empty; if (radioman.checked) { stugender = "1"; } else { stugender = "0"; } //下拉框绑定数据 int gid = geadidname(); //联系电话 string stuphone = textphone.text; //地址 string stuaddress = textaddress.text; //日期 datetime dt = datebirthday.value; //邮箱 string stuemail = textemail.text; //loginpwd, studentname, gender, gradeid, phone, address, birthday, email string sql = @"update student set studentname='" + stuname + "',gender=" + stugender + ",gradeid='" + gid + "',phone='" + stuphone + "',address='" + stuaddress + "',birthday='" + dt + "',email='" + stuemail + "' where studentno='" + textno.text + "'"; string str = "data source=.;initial catalog=myschool;uid=sa;"; sqlconnection con = new sqlconnection(str); sqlcommand cmd = new sqlcommand(sql, con); con.open(); int count = cmd.executenonquery(); if (count > 0) { frmselect.selectdata(); messagebox.show("修改成功"); } con.close(); }
以上就是关于学生管理系统的实现的关键代码,希望对大家的学习有所帮助,大家可以动手制作学生管理系统,对学生管理系统功能进行扩充。