C#与SQL数据库学生成绩管理系统完整代码

2025-06-14

图4.1

该界面是学生成绩管理系统的登录界面,可以选择作为学生,管理员或者教师身份登录。每一个进入系统的人都会看到当前的时间,在登录时只有用户名,密码,与身份相符合时才能进入系统,否则登录无法成功。 using System;

using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;

using System.Threading.Tasks; using System.Windows.Forms; using System.Data.SqlClient;

namespace WindowsFormsApplication1 {

public partial class Form1 : Form {

static public string sn, sub; public Form1() {

InitializeComponent(); }

Form2 fr2 = new Form2(); Form3 fr3 = new Form3(); Form4 fr4 = new Form4();

private void Form1_Load(object sender, EventArgs e) {

timer1.Start(); }

private void label1_Click(object sender, EventArgs e) {

}

private void button1_Click(object sender, EventArgs e) {

string constr = \ID=ywj;Initial Catalog=studentscore;Data Source=YANJING\; SqlConnection conn = new SqlConnection(constr); conn.Open();

if (textname.Text == \ || textpassword.Text == \) MessageBox.Show(\信息不全,请不要遗漏信息!\); if (rbtnmanager.Checked) {

string cstr = \类别='管理员' and 用户名='\ + textname.Text.Trim() + \密码='\ + textpassword.Text.Trim() + \; SqlCommand comm = new SqlCommand(cstr, conn); SqlDataReader dr = comm.ExecuteReader(); if (dr.Read()) {

sn = textname.Text.Trim(); fr4.Show(); this.Visible = false; ; } else {

MessageBox.Show(\密码或用户名出错,请重新输入!\); textname.Text = \; textpassword.Text = \; } }

if (rbtnteacher.Checked) {

string cstr = \类别='教师' and 用户名='\ + textname.Text.Trim() + \密码='\ + textpassword.Text.Trim() + \; SqlCommand comm = new SqlCommand(cstr, conn); SqlDataReader dr = comm.ExecuteReader(); if (dr.Read()) {

sn = textname.Text.Trim(); sub = dr.GetValue(3).ToString(); fr3.Show(); this.Visible = false;

} else {

MessageBox.Show(\密码或用户名出错,请重新输入!\); textname.Text = \; textpassword.Text = \; } }

if (rbtnstudent.Checked) {

string cstr = \类别='学生' and 用户名='\ + textname.Text.Trim() + \密码='\ + textpassword.Text.Trim() + \; SqlCommand comm = new SqlCommand(cstr, conn); SqlDataReader dr = comm.ExecuteReader(); if (dr.Read()) {

sn = textname.Text.Trim(); fr2.Show(); this.Visible = false;

} else {

MessageBox.Show(\密码或用户名出错,请重新输入!\); textname.Text = \; textpassword.Text = \; } }

conn.Close(); conn.Dispose(); }

private void button2_Click(object sender, EventArgs e) {

Application.Exit(); }

private void timer1_Tick(object sender, EventArgs e) {

label4.Text = \当前时间:\ + DateTime.Now.ToLongDateString() + \ + DateTime.Now.ToLongTimeString(); }

} }

4.2学生成绩管理

图4.2

设计过程:

此部分主要针对学生信息的管理,可以查询学生的所有成绩信息,实现成绩的添加、删除、修改、计算平均分等功能。还可以修改当前用户下的密码。

private void Form2_Load(object sender, EventArgs e) {

label1.Text = Form1.sn + \同学,欢迎你进入成绩管理系统!\; timer1.Start();

groupBox1.Visible = false; groupBox2.Visible = false; }

private void button1_Click(object sender, EventArgs e) {

}

private void button3_Click(object sender, EventArgs e)

{

// string constr = \ID=BINIANDOUKOU\\administrator;Initial Catalog=studentscore;Data Source=BINIANDOUKOU\\\\SQLEXPRESS\

//SqlConnection conn = new SqlConnection(constr); //conn.Open();

//SqlDataAdapter da = new SqlDataAdapter(\姓名=\

//DataSet ds = new DataSet(); //da.Fill(ds, \ //dataGridView1.DataSource = ;

}

private void toolStripButton1_Click(object sender, EventArgs e) {

dataGridView1.Visible = true; groupBox1.Visible = false; groupBox2.Visible = false;

string constr = \ID=ywj;Initial Catalog=studentscore;Data Source=YANJING\; SqlConnection conn = new SqlConnection(constr); conn.Open();

SqlDataAdapter da = new SqlDataAdapter(\姓名='\ + Form1.sn.Trim() + \, conn);//----详细信息 DataSet ds = new DataSet(); da.Fill(ds, \);

dataGridView1.DataSource = ds.Tables[\].DefaultView; conn.Close(); conn.Dispose(); }

private void toolStripButton2_Click(object sender, EventArgs e) {

}

private void toolStripButton4_Click(object sender, EventArgs e) {

groupBox1.Visible = true; }

private void button1_Click_1(object sender, EventArgs e) {

string constr = \ID=ywj;Initial Catalog=studentscore;Data Source=YANJING\; SqlConnection conn = new SqlConnection(constr); conn.Open();

if (textnpd.Text != textpassword.Text) { MessageBox.Show(\密码输入有


C#与SQL数据库学生成绩管理系统完整代码.doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:第二章中华人民共和国安全生产法试题库

相关阅读
本类排行
× 游客快捷下载通道(下载后可以自由复制和排版)

下载本文档需要支付 7

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:xuecool-com QQ:370150219