C#编写简易的学生成绩查询

C#学生成绩管理系统
本文介绍了一款基于C#的学生成绩管理系统,包括用户登录、学生信息管理、成绩查询等功能。系统采用Visual Studio 2010开发,并利用SQL Server 2008作为数据库,提供了详细的操作步骤与代码示例。

C#编写简易的学生成绩查询

 

什么是学生成绩查询系统?

 

使用C#语言编写的一个可安装的简单CS系统,实现了用户登录,学生信息添加,成绩修改,删除,查询等功能

 

开发环境

开发环境

visual studio2010(新版本2015,2017也可)

visual studio2010(sql2008数据库)

 

安装步骤

 

 

 

 

 

 

功能展示

 

 

笔者在这里详情下一下制作步骤

 

1. 首先是登录界面及代码

2.

3. 先是创建一个windows窗体应用程序把名称改成学生成绩管理系统

4. 然后添加一个groupBox控件并且把名称改为登陆,然后添加两个lable控件分别为账户密码  两个txtbox控件 一个button控件

5.   using System;

6.   using System.Collections.Generic;

7.   using System.ComponentModel;

8.   using System.Data;

9.   using System.Drawing;

10. using System.Linq;

11. using System.Text;

12. using System.Windows.Forms;

13.  

14. namespace 测a试º?

15. {

16.     public partial class login : Form

17.     {

18.         public login()

19.         {

20.             InitializeComponent();

21.         }

22.  

23.         private void textBox1_TextChanged(object sender, EventArgs e)

24.         {

25.  

26.         }

27.  

28.         private void button1_Click(object sender, EventArgs e)

29.         {

30.             if (textBox1.Text == string.Empty)//如果文本为空

31.             {

32.                 MessageBox.Show( "账?户¡ì不?能¨¹为a空?","错䨪误¨®提¬¨¢示º?",MessageBoxButtons.OK,MessageBoxIcon.Error);//弹出消息框

33.             }

34.             if (textBox1.Text == "一°?班㨤三¨y组Á¨¦" && textBox2.Text == "1403")//如果账户密码正确

35.             {

36.          studentmange frm=new studentmange();//实例学生成绩化窗体

37.                 frm.Show();//显示窗体

38.                 this.Visible=false;//隐藏登陆窗体

39.             

40.             }

41.             

42.         }

43.  

44.         private void login_Load(object sender, EventArgs e)

45.         {

46.  

47.         }

48.     }

49. }

 

添加成绩查询窗体

与第一个窗体一样添加控件  多了一个dataGridView控件

 

 

代码如下:

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Data.SqlClient;

 

 

namespace 测a试º?

{

    public partial class studentmange : Form

    {

        public void shuju()//创建方法

        {

            String strcon = "server=(bds288146407.my3w.com);database=bds288146407_db;uid= bds288146407;pwd=chen419216";//连接数据库

            SqlConnection conn = new SqlConnection(strcon);

            conn.Open();//打开数据库

            String sql = "select * from 成¨¦绩¡§表À¨ª where 学¡ì号?='" + this.textBox3.Text.Trim() + "'and 课?程¨¬名?称?='" + this.textBox4.Text.Trim() + "'";//输入sql查询语句

          

 

 

            SqlDataAdapter reae = new SqlDataAdapter(sql, conn);

            DataSet ds = new DataSet();//填充数据

            reae.Fill(ds);

            dataGridView2.DataSource = ds.Tables[0];//显示数据

        }

      

        public studentmange()

        {

            InitializeComponent();

        }

 

        private void button2_Click(object sender, EventArgs e)

        {

            if (textBox1.Text == string.Empty)//如果文本框为空

            {

                MessageBox.Show("不?能¨¹为a空?", "错䨪误¨®提¬¨¢示º?", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;

            }

            if (textBox2.Text == string.Empty)

            {

                MessageBox.Show("不?能¨¹为a空?", "错䨪误¨®提¬¨¢示º?", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;//结束查询

            }

 

            String strcon = "server=(bds288146407.my3w.com);database=bds288146407_db;uid=bds288146407;pwd=chen419216";

            SqlConnection conn = new SqlConnection(strcon);

            conn.Open();

            String sql = "select * from 成¨¦绩¡§表À¨ª where 姓?名?='"+ this.textBox1.Text.Trim()+ "'and 学¡ì号?='"+this.textBox2.Text.Trim()+"'";

            SqlCommand cmd = new SqlCommand(sql, conn);

 

         

            /this.dataGridView1.DataSource = DataBindings;

 

 

            SqlDataAdapter reae = new SqlDataAdapter(sql, conn);

            DataSet ds = new DataSet();

            reae.Fill(ds);

            dataGridView1.DataSource = ds.Tables[0];

         

 

         

 

        }

 

        private void button1_Click(object sender, EventArgs e)

        {

            textBox1.Text = "";

            textBox2.Text = "";

        }

 

        private void Form1_Load(object sender, EventArgs e)

        {

          

        }

 

        private void textBox4_TextChanged(object sender, EventArgs e)

        {

 

        }

 

        private void button4_Click(object sender, EventArgs e)

        {

         

 

            if (textBox3.Text == string.Empty)

            {

                MessageBox.Show("不?能¨¹为a空?", "错䨪误¨®提¬¨¢示º?", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;

            }

            if (textBox4.Text == string.Empty)

            {

                MessageBox.Show("不?能¨¹为a空?", "错䨪误¨®提¬¨¢示º?", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;

            }

            if (textBox5.Text == string.Empty)

            {

                MessageBox.Show("不?能¨¹为a空?", "错䨪误¨®提¬¨¢示º?", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;

            }

 

            String strcon = "server=(bds288146407.my3w.com);database=bds288146407_db;uid= bds288146407;pwd=chen419216";

            SqlConnection conn = new SqlConnection(strcon);

            conn.Open();

            string sql = "update 成¨¦绩¡§表À¨ª set 课?程¨¬名?称?='"+this.textBox4.Text.Trim()+"',成¨¦绩¡§='"+this.textBox5.Text.Trim()+"'where 学¡ì号?='"+this.textBox3.Text.Trim()+"'";

            SqlCommand cmd = new SqlCommand(sql, conn);

            cmd.ExecuteNonQuery();

            shuju();//方法调用

            conn.Close();

 

        }

 

        private void button3_Click(object sender, EventArgs e)

        {

 

            String strcon = "server=(bds288146407.my3w.com);database=bds288146407_db;uid= bds288146407;pwd=chen419216";

            SqlConnection conn = new SqlConnection(strcon);

            conn.Open();

            string sql = "delete  成¨¦绩¡§表À¨ª where 学¡ì号?='" + this.textBox3.Text.Trim() + "'";

            SqlCommand cmd = new SqlCommand(sql, conn);//数据采集

           

            cmd.ExecuteNonQuery();//执行查询

            MessageBox.Show("删¦?除y成¨¦功|");

            String sql2 = "select * from 成¨¦绩¡§表À¨ª";

          SqlDataAdapter reae = new SqlDataAdapter(sql2, conn);

            DataSet ds = new DataSet();

            reae.Fill(ds);

            dataGridView2.DataSource = ds.Tables[0];

            conn.Close();

        }

 

        private void button5_Click(object sender, EventArgs e)

        {

 

            String strcon = "server=(bds288146407.my3w.com);database=bds288146407_db;uid= bds288146407;pwd=chen419216";

            SqlConnection conn = new SqlConnection(strcon);

            conn.Open();

            string sql = "insert into  成¨¦绩¡§表À¨ª(姓?名?,学¡ì号?,课?程¨¬名?称?,成¨¦绩¡§,年¨º龄¢?) values ('" + this.textBox6.Text.Trim() + "','" + this.textBox7.Text.Trim() + "','" + this.textBox8.Text.Trim() + "','" +Convert.ToInt32( this.textBox9.Text.Trim()) + "','" + this.textBox10.Text.Trim() + "') ";

            SqlCommand cmd = new SqlCommand(sql, conn);

 

            cmd.ExecuteNonQuery();

            MessageBox.Show("添¬¨ª加¨®成¨¦功|");

            String sql2 = "select * from 成¨¦绩¡§表À¨ª";

            SqlDataAdapter reae = new SqlDataAdapter(sql2, conn);

            DataSet ds = new DataSet();

            reae.Fill(ds);

            dataGridView3.DataSource = ds.Tables[0];

            conn.Close();

        }

 

        private void button6_Click(object sender, EventArgs e)

        {

            Application.Exit();

        }

 

        private void toolStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)

        {

 

        }

 

        private void statusStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)

        {

 

        }

 

        private void toolStrip1_ItemClicked_1(object sender, ToolStripItemClickedEventArgs e)

        {

 

        }

    }

}

 

数据库ER图

 

转载于:https://www.cnblogs.com/qufeiba/p/7056840.html

C#.net实现学生成绩管理系统 namespace 学生成绩管理系统 { partial class Formlogin { /// /// 必需的设计器变量。 /// private System.ComponentModel.IContainer components = null; /// /// 清理所有正在使用的资源。 /// /// 如果应释放托管资源,为 true;否则为 false。 protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows 窗体设计器生成的代码 /// /// 设计器支持所需的方法 - 不要 /// 使用代码编辑器修改此方法的内容。 /// private void InitializeComponent() { this.labeluser = new System.Windows.Forms.Label(); this.textBoxuser = new System.Windows.Forms.TextBox(); this.labelcode = new System.Windows.Forms.Label(); this.textBoxcode = new System.Windows.Forms.TextBox(); this.buttonin = new System.Windows.Forms.Button(); this.buttonout = new System.Windows.Forms.Button(); this.SuspendLayout(); // // labeluser // this.labeluser.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.labeluser.Location = new System.Drawing.Point(31, 50); this.labeluser.Name = "labeluser"; this.labeluser.Size = new System.Drawing.Size(55, 26); this.labeluser.TabIndex = 0; this.labeluser.Text = "用户名"; this.labeluser.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // textBoxuser // this.textBoxuser.Location = new System.Drawing.Point(126, 55); this.textBoxuser.Name = "textBoxuser"; this.textBoxuser.Size = new System.Drawing.Size(112, 21); this.textBoxuser.TabIndex = 1; // // labelcode // this.labelcode.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.labelcode.Location = new System.Drawing.Point(31, 124); this.labelcode.Name = "labelcode"; this.labelcode.Size = new System.Drawing.Size(55, 23); this.labelcode.TabIndex = 2; this.labelcode.Text = "密码"; this.labelcode.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // textBoxcode // this.textBoxcode.Location = new System.Drawing.Point(126, 124); this.textBoxcode.Name = "textBoxcode"; this.textBoxcode.PasswordChar = '*'; this.textBoxcode.Size = new System.Drawing.Size(112, 21); this.textBoxcode.TabIndex = 3; // // buttonin // this.buttonin.Location = new System.Drawing.Point(34, 200); this.buttonin.Name = "buttonin"; this.buttonin.Size = new System.Drawing.Size(75, 23); this.buttonin.TabIndex = 4; this.buttonin.Text = "登陆"; this.buttonin.UseVisualStyleBackColor = true; this.buttonin.Click += new System.EventHandler(this.buttonin_Click); // // buttonout // this.buttonout.Location = new System.Drawing.Point(163, 200); this.buttonout.Name = "buttonout"; this.buttonout.Size = new
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值