本篇内容主要讲解“ASP.NET如何编写学生管理系统”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“ASP.NET如何编写学生管理系统”吧!
坚守“ 做人真诚 · 做事靠谱 · 口碑至上 · 高效敬业 ”的价值观,专业网站建设服务10余年为成都地磅秤小微创业公司专业提供企业网站制作营销网站建设商城网站建设手机网站建设小程序网站建设网站改版,从内容策划、视觉设计、底层架构、网页布局、功能开发迭代于一体的高端网站建设服务。ASP.NET 是开源,跨平台,高性能,轻量级的 Web 应用构建框架,常用于通过 HTML、CSS、JavaScript 以及服务器脚本来构建网页和网站。
学生管理系统所需要的具体控件和主要属性:
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(); }
到此,相信大家对“ASP.NET如何编写学生管理系统”有了更深的了解,不妨来实际操作一番吧!这里是创新互联建站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!