您好,登錄后才能下訂單哦!
本篇內容主要講解“ASP.NET如何編寫學生管理系統(tǒng)”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“ASP.NET如何編寫學生管理系統(tǒng)”吧!
ASP.NET 是開源,跨平臺,高性能,輕量級的 Web 應用構建框架,常用于通過 HTML、CSS、JavaScript 以及服務器腳本來構建網頁和網站。
學生管理系統(tǒng)所需要的具體控件和主要屬性:
1、登錄窗體
基本控件:
label(標簽控件)
主要屬性:Image(在標簽上顯示的圖像)
Text(在標簽上顯示的文本)
TextBox(文本框控件)
主要屬性:PasswordChar(指示在作為密碼框時,文本框中顯示的字符,而不是實際輸入的文本)
Button(按鈕控件)
ComboBox(下拉框)屬性:SelectedItem:獲取當前選定的項
事件:Click(單擊控件時發(fā)生)
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是事件源,表示發(fā)生了這個事件的對象,事件發(fā)生中,事件源就是按鈕。
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如何編寫學生管理系統(tǒng)”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續(xù)學習!
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。