本篇內(nèi)容主要講解“ASP.NET如何編寫學生管理系統(tǒng)”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“ASP.NET如何編寫學生管理系統(tǒng)”吧!

ASP.NET 是開源,跨平臺,高性能,輕量級的 Web 應用構建框架,常用于通過 HTML、CSS、JavaScript 以及服務器腳本來構建網(wǎng)頁和網(wǎng)站。
學生管理系統(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是事件參數(shù)(EventArgs)對象,不同的事件會有不同的參數(shù)。
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";
}
//下拉框綁定數(shù)據(jù)
int gid = GeadIdName();
//聯(lián)系電話
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關聯(lián)
lvlist.Items.Add(LvItem);
}
dr.Close();
}
}
}
catch (Exception)
{
throw;
}
finally
{
con.Close();
}
//窗體Load的事件中調(diào)用
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";
}
//下拉框綁定數(shù)據(jù)
int gid = GeadIdName();
//聯(lián)系電話
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)”有了更深的了解,不妨來實際操作一番吧!這里是創(chuàng)新互聯(lián)建站,更多相關內(nèi)容可以進入相關頻道進行查詢,關注我們,繼續(xù)學習!
新聞標題:ASP.NET如何編寫學生管理系統(tǒng)-創(chuàng)新互聯(lián)
本文地址:http://chinadenli.net/article46/ejeeg.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供響應式網(wǎng)站、定制開發(fā)、網(wǎng)站改版、微信小程序、移動網(wǎng)站建設、用戶體驗
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容