ASP.NET实现学⽣管理系统学⽣管理系统所需要的具体控件和主要属性:
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();
asp文件管理系统
}
}
}
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();
}
更多学习资料请关注专题《》。
以上就是关于学⽣管理系统的实现的关键代码,希望对⼤家的学习有所帮助,⼤家可以动⼿制作学⽣管理系统,对学⽣管理系统功能进⾏扩充。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。