【2019-2020春學期】數據庫實驗大作業

實驗目的:

使用SQL Server 和Visual Studio實現一個學生信息管理系統。

實驗內容:

設計並實現“學生信息管理系統”,該系統的主要任務爲管理學生的信息。用戶爲學生和系統管理員。
在進入頁面之前需要進行登錄,在學生在學號和密碼正確的情況下進入系統,管理員在工號和密碼對應的情況下進入系統。
管理員可以增加、刪除、修改、查詢管理員的個人信息,增加、刪除、修改、查詢學生的個人信息,添加、查詢課程,以及對學生的成績進行錄入、統計、修改和查詢,還可以修改個人的密碼。
學生可以查詢學習成績,修改個人的密碼,還可以查詢、選擇課程。
在這裏插入圖片描述

代碼:

數據準備:

DROP DATABASE IF EXISTS student_information_management_system;  

CREATE DATABASE student_information_management_system;  

USE student_information_management_system;

DROP TABLE IF EXISTS Student
DROP TABLE IF EXISTS Manage
DROP TABLE IF EXISTS Course
DROP TABLE IF EXISTS SC

CREATE TABLE Student          
 (	
 學號 NCHAR(10) PRIMARY KEY NOT NULL,        /* 列級完整性約束條件,學號是主碼*/                  
 姓名 NCHAR(10) NOT NULL,          
 性別 NCHAR(2) CHECK(性別 IN ('男','女')) NOT NULL,
 出生日期 CHAR(10),
 民族 NCHAR(10),
 專業 NCHAR(20) NOT NULL,
 年級 NCHAR(4) NOT NULL,
 籍貫 NCHAR(25),
 手機號碼 CHAR(11)NOT NULL,
 密碼 NCHAR(35) NOT NULL,
 ); 

 CREATE TABLE Manage          
 (	
 工號 NCHAR(10) PRIMARY KEY NOT NULL,        /* 列級完整性約束條件,學號是主碼*/                  
 姓名 NCHAR(10) NOT NULL,          
 性別 NCHAR(2) CHECK(性別 IN ('男','女'))NOT NULL,
 出生日期 NCHAR(10),
 籍貫 NCHAR(25),
 手機號碼 CHAR(11)NOT NULL,
 民族 NCHAR(10),
 密碼 NCHAR(35) NOT NULL,
 ); 

 CREATE TABLE  Course
 (	
 課程號 NCHAR(10) PRIMARY KEY NOT NULL,
 課程名 NCHAR(10) NOT NULL,            
 學分 SMALLINT NOT NULL,               	                      
 上課地點 NCHAR(20) NOT NULL,
 上課時間 NCHAR(20)NOT NULL 
 ); 

 CREATE TABLE  SC
 (
 學號 NCHAR(10) NOT NULL, 
 姓名 NCHAR(10),
 課程號 NCHAR(10)NOT NULL,
 課程名 NCHAR(10),
 成績 SMALLINT CHECK(成績>=0 AND 成績<=100),
 學分 SMALLINT ,
 PRIMARY KEY (學號,課程號),                     /* 主碼由兩個屬性構成,必須作爲表級完整性進行定義*/
 FOREIGN KEY (學號) REFERENCES Student(學號),  /* 表級完整性約束條件,學號是外碼,被參照表是Student */
 FOREIGN KEY (課程號)REFERENCES Course(課程號),     /* 表級完整性約束條件, 工號是外碼,被參照表是Course*/
 ); 

INSERT  INTO  Student(學號,姓名,性別,出生日期,民族,專業,年級,籍貫,手機號碼,密碼) VALUES ('201215121','李勇','男','2000-11-03','漢族','數學信息專業','18','北京市','123123213','41b2e380f4ee72d92e4e1b61672d07ed');
INSERT  INTO  Student(學號,姓名,性別,出生日期,民族,專業,年級,籍貫,手機號碼,密碼) VALUES ('201215122','劉晨','男','2000-01-03','漢族','網絡安全專業','18','上海市','1231232222','4fe3a5afd4d66bc2768870421bef6d80');
INSERT  INTO  Student(學號,姓名,性別,出生日期,民族,專業,年級,籍貫,手機號碼,密碼) VALUES ('201215123','佟露露','女','1998-02-13','漢族','生命科學專業','16','福建省','1231239873','aed333517421ba701dcfeaf3ee0da619');
INSERT  INTO  Student(學號,姓名,性別,出生日期,民族,專業,年級,籍貫,手機號碼,密碼) VALUES ('201215124','王敏','女','1999-07-30','漢族','通信專業','17','河北省','1231239803','5c15d3390d851205843a7e2c3a3a3d12');
INSERT  INTO  Student(學號,姓名,性別,出生日期,民族,專業,年級,籍貫,手機號碼,密碼) VALUES ('201215125','張麗','女','2001-04-21','漢族','航空航天專業','19','江西省','1231234563','f5579fdd1b92e1cecbe534a5e74cecfd');
INSERT  INTO  Student(學號,姓名,性別,出生日期,民族,專業,年級,籍貫,手機號碼,密碼) VALUES ('201215126','張扉','男','2000-06-30','漢族','計算機科學與技術專業','18','北京市','1232342213','9f83c11348a0a3a6259963823be1870f');
INSERT  INTO  Student(學號,姓名,性別,出生日期,民族,專業,年級,籍貫,手機號碼,密碼) VALUES ('201215127','顧依涼','男','2000-08-20','漢族','生命科學專業','18','貴州省','1231276513','b98a4565eb67c24a9481eb96d202d0e5');
INSERT  INTO  Student(學號,姓名,性別,出生日期,民族,專業,年級,籍貫,手機號碼,密碼) VALUES ('201215128','白雪','女','2001-03-23','漢族','通信專業','19','黑龍江省','1311232213','206111b43716ab18328809c64bef1fff');
INSERT  INTO  Student(學號,姓名,性別,出生日期,民族,專業,年級,籍貫,手機號碼,密碼) VALUES ('201215129','趙岑','男','2001-04-19','漢族','計算機科學與技術專業','19','吉林省','1345232213','cfb159592100391fce3640ce840dcd3d');
INSERT  INTO  Student(學號,姓名,性別,出生日期,民族,專業,年級,籍貫,手機號碼,密碼) VALUES ('201215120','林琳','女','2000-03-09','漢族','生命科學專業','18','四川省','1239802213','4c81c88cd7709d8b28d558c8f8af22d2');
INSERT  INTO  Student(學號,姓名,性別,出生日期,民族,專業,年級,籍貫,手機號碼,密碼) VALUES ('201215130','宋言','男','2002-07-03','漢族','航空航天專業','19','安徽','1234562213','415dfeb3e03aa46004ba95342897e702');
INSERT  INTO  Student(學號,姓名,性別,出生日期,民族,專業,年級,籍貫,手機號碼,密碼) VALUES ('201215131','衛琬','女','2000-11-03','漢族','通信專業','18','江西省','1231098713','039552cd56eb9fb800416d384052a0b0');
INSERT  INTO  Student(學號,姓名,性別,出生日期,民族,專業,年級,籍貫,手機號碼,密碼) VALUES ('201215132','韓曉夢','女','2000-12-09','漢族','數學信息專業','18','黑龍江省','1231342313','a2f5e908f5e96a9e44fea614fc3c0837');
INSERT  INTO  Student(學號,姓名,性別,出生日期,民族,專業,年級,籍貫,手機號碼,密碼) VALUES ('201215133','李祁','男','2000-08-17','漢族','計算機科學與技術專業','18','北京市','1239872213','40325844eaa57b823e4cc8f524ac43e7');
INSERT  INTO  Student(學號,姓名,性別,出生日期,民族,專業,年級,籍貫,手機號碼,密碼) VALUES ('201215134','鄭頌雨','男','2002-06-12','漢族','生命科學專業','18','四川省','1231000213','6a9a16592c30de3aed9cb898886b2a6c');

SELECT * FROM Student

INSERT  INTO  Manage(工號,姓名,性別,出生日期,籍貫,手機號碼,民族,密碼) VALUES ('201203','張珊','女','1982-01-01','四川省','13812345678','漢族','9365f8127adaa91c6ed8433cd9f32c24');
INSERT  INTO  Manage(工號,姓名,性別,出生日期,籍貫,手機號碼,民族,密碼) VALUES ('201204','李姒','女','1993-11-01','江西省','13898762312','漢族','d01bb7551d54d9c0806d79233b6fe10b');
INSERT  INTO  Manage(工號,姓名,性別,出生日期,籍貫,手機號碼,民族,密碼) VALUES ('201205','王武','男','1989-02-01','黑龍江省','13154342378','漢族','205ded2984e1daf6e3b9373767e8bf6e');
INSERT  INTO  Manage(工號,姓名,性別,出生日期,籍貫,手機號碼,民族,密碼) VALUES ('201206','錢珥','女','1982-01-01','安徽','13819334328','漢族','2d0cac1b87699da50b07937dcee15a05');
INSERT  INTO  Manage(工號,姓名,性別,出生日期,籍貫,手機號碼,民族,密碼) VALUES ('201207','趙依','女','1993-11-01','江西省','13898762312','漢族','28689f39401b4eaa9fc79efde978ca11');
INSERT  INTO  Manage(工號,姓名,性別,出生日期,籍貫,手機號碼,民族,密碼) VALUES ('201208','孫柳','男','1987-05-16','上海市','13159877348','漢族','bef90937301f701a5c39280d255e9e86');
SELECT * FROM Manage

INSERT  INTO Course(課程號,課程名,學分,上課地點,上課時間)VALUES ('1','數據庫',4,'一教101','週二7-9節');
INSERT  INTO Course(課程號,課程名,學分,上課地點,上課時間)VALUES ('2','高等數學',2,'三教212','週一1-4節');
INSERT  INTO Course(課程號,課程名,學分,上課地點,上課時間)VALUES ('3','信息系統',2,'二教103','週三7-9節');
INSERT  INTO Course(課程號,課程名,學分,上課地點,上課時間)VALUES ('4','操作系統',1,'一教601','週二1-2節');
INSERT  INTO Course(課程號,課程名,學分,上課地點,上課時間)VALUES ('5','數據結構',3,'三教101','週五5-6節');
INSERT  INTO Course(課程號,課程名,學分,上課地點,上課時間)VALUES ('6','數據處理',2,'二教211','週四2-4節');
INSERT  INTO Course(課程號,課程名,學分,上課地點,上課時間)VALUES ('7','Pascal語言',4,'一教101','週三3-4節');
SELECT * FROM Course


INSERT  INTO SC(學號,姓名,課程號,課程名,成績,學分) VALUES ('201215122 ','劉晨','1','數據庫',80,4);
INSERT  INTO SC(學號,姓名,課程號,課程名,成績,學分) VALUES ('201215123 ','佟露露','1','數據庫',60,4);
INSERT  INTO SC(學號,姓名,課程號,課程名,成績,學分) VALUES ('201215126 ','張扉','1','數據庫',70,4);
INSERT  INTO SC(學號,姓名,課程號,課程名,成績,學分) VALUES ('201215129 ','趙岑','1','數據庫',97,4);
INSERT  INTO SC(學號,姓名,課程號,課程名,成績,學分) VALUES ('201215131 ','衛琬','1','數據庫',84,4);
INSERT  INTO SC(學號,姓名,課程號,課程名,成績,學分) VALUES ('201215134 ','鄭頌雨','2','高等數學',88,2);
INSERT  INTO SC(學號,姓名,課程號,課程名,成績,學分) VALUES ('201215121 ','李勇','2','高等數學',56,0);
INSERT  INTO SC(學號,姓名,課程號,課程名,成績,學分) VALUES ('201215125 ','張麗','2','高等數學',70,2);
INSERT  INTO SC(學號,姓名,課程號,課程名,成績,學分) VALUES ('201215127 ','顧依涼','2','高等數學',77,2);
INSERT  INTO SC(學號,姓名,課程號,課程名,成績,學分) VALUES ('201215133 ','李祁','2','高等數學',84,2);
INSERT  INTO SC(學號,姓名,課程號,課程名,成績,學分) VALUES ('201215124 ','王敏','3','信息系統',88,2);
INSERT  INTO SC(學號,姓名,課程號,課程名,成績,學分) VALUES ('201215128 ','白雪','4','操作系統',56,0);
INSERT  INTO SC(學號,姓名,課程號,課程名,成績,學分) VALUES ('201215120 ','林琳','5','數據結構',70,3);
INSERT  INTO SC(學號,姓名,課程號,課程名,成績,學分) VALUES ('201215130 ','宋言','6','數據處理',77,2);
INSERT  INTO SC(學號,姓名,課程號,課程名,成績,學分) VALUES ('201215132 ','韓曉夢','7','Pascal語言',84,4);
UPDATE SC SET 學分=0 WHERE 成績<60
SELECT * FROM SC

觸發器

--在SC表中如果修改學號會對應修改姓名
IF(OBJECT_ID('show_Sname') is not null)        -- 判斷名爲 show_Sname 的觸發器是否存在
DROP TRIGGER show_Sname        -- 刪除觸發器
GO

CREATE TRIGGER show_Sname
ON SC  	         
FOR UPDATE
AS 
	declare @NEWSno NCHAR(10),
			@Sname NCHAR(10);
IF(UPDATE(學號))
	BEGIN
	SELECT @NEWSno =學號 FROM INSERTED
	SELECT @Sname =姓名 FROM Student WHERE 學號=@NEWSno
	UPDATE SC SET 姓名=@Sname WHERE 學號=@NEWSno

END;

--在SC表中如果修改課程號會對應修改課程名
IF(OBJECT_ID('show_Cname') is not null)        -- 判斷名爲 show_Cname 的觸發器是否存在
DROP TRIGGER show_Cname        -- 刪除觸發器
GO

CREATE TRIGGER show_Cname
ON SC  	         
FOR UPDATE
AS 
	declare @NEWCno NCHAR(10),
			@Cname NCHAR(10),
			@credit SMALLINT;
IF(UPDATE(課程號))
	BEGIN
	SELECT @NEWCno =課程號 FROM INSERTED
	SELECT @Cname =課程名 FROM Course WHERE 課程號=@NEWCno
	SELECT @credit = 學分 FROM Course WHERE 課程號=@NEWCno
	UPDATE SC SET 課程名=@Cname WHERE 課程號=@NEWCno
	UPDATE SC SET 學分=@credit WHERE 課程號=@NEWCno AND 成績>=60
	UPDATE SC SET 學分=0 WHERE 課程號=@NEWCno AND 成績<60

END;

--在SC表中如果修改成績,成績大於60時,學分獲得,否則爲0
IF(OBJECT_ID('show_credit') is not null)        -- 判斷名爲 show_credit 的觸發器是否存在
DROP TRIGGER show_credit        -- 刪除觸發器
GO

CREATE TRIGGER show_credit
ON SC  	         
FOR UPDATE
AS 
	declare @NEWgrade SMALLINT,
			@Sno NCHAR(10),
			@Cno NCHAR(10),
			@credit SMALLINT;
IF(UPDATE(成績))
	BEGIN
	SELECT @NEWgrade = 成績 FROM INSERTED
	SELECT @Sno = 學號 FROM DELETED
	SELECT @Cno = 課程號 FROM DELETED 
	SELECT @credit  =學分 FROM Course WHERE 課程號=@Cno
	UPDATE SC SET 學分=0 WHERE 課程號=@Cno AND 成績<60
	UPDATE SC SET 學分=@credit WHERE 課程號=@Cno AND 成績>=60

END;

--在Course表中如果修改學分,SC表中的對應學分也要修改
IF(OBJECT_ID('change_credit') is not null)        -- 判斷名爲 change_credit 的觸發器是否存在
DROP TRIGGER change_credit        -- 刪除觸發器
GO
CREATE TRIGGER change_credit
ON Course  	         
FOR UPDATE
AS 
	declare @Cno NCHAR(10),
			@credit SMALLINT;
IF(UPDATE(學分))
	BEGIN
	SELECT @Cno = 課程號 FROM DELETED 
	SELECT @credit  =學分 FROM INSERTED
	UPDATE SC SET 學分=0 WHERE 課程號=@Cno AND 成績<60
	UPDATE SC SET 學分=@credit WHERE 課程號=@Cno AND 成績>=60

END;

Class1.cs文件:
目的:定義全局變量,保存輸入的賬號,以此顯示對應的信息。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 學生信息管理系統
{
    public class Class1
    {
        public static string UserID;
    }
}

登錄界面:
在這裏插入圖片描述

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 學生信息管理系統
{
    public partial class Form1 : Form
    {
        
        public Form1()
        {
            InitializeComponent();
        }
        public string code;
        private void Login_Load_1(object sender, EventArgs e)
        {
            //隨機實例化 
            Random ran = new Random();
            int number;
            char code1;
            //取五個數 
            for (int i = 0; i < 5; i++)
            {
                number = ran.Next();
                if (number % 2 == 0)
                    code1 = (char)('0' + (char)(number % 10));
                else
                    code1 = (char)('A' + (char)(number % 26)); //轉化爲字符 

                this.code += code1.ToString();
            }

            label5.Text = code;
        }
        public static string EncryptWithMD5(string source)
        {
            byte[] sor = Encoding.UTF8.GetBytes(source);
            MD5 md5 = MD5.Create();
            byte[] result = md5.ComputeHash(sor);
            StringBuilder strbul = new StringBuilder(40);
            for (int i = 0; i < result.Length; i++)
            {
                strbul.Append(result[i].ToString("x2"));//加密結果"x2"結果爲32位,"x3"結果爲48位,"x4"結果爲64位
            }
            return strbul.ToString();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            //隨機實例化 
            Random ran = new Random();
            int number;
            char code1;
            //取五個數 
            for (int i = 0; i < 5; i++)
            {
                number = ran.Next();
                if (number % 2 == 0)
                    code1 = (char)('0' + (char)(number % 10));
                else
                    code1 = (char)('A' + (char)(number % 26)); //轉化爲字符 

                this.code += code1.ToString();
            }

            label5.Text = code;
        }
        private void textBox1_TextChanged(object sender,EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string username = textBox1.Text.Trim();  //取出賬號
            string password = EncryptWithMD5(textBox2.Text.Trim());  //取出密碼並加密

            // if (username == "admin")
            //   password = "123";//測試用例,便於初始化時候的 admin 密碼 123可以順利登陸。程序完成後可註釋掉這行代碼。

            //string connstr = ConfigurationManager.ConnectionStrings["connectionString"].ToString(); //讀取連接字符串
            string myConnString = "Data Source=.;Initial Catalog=student_information_management_system;Persist Security Info=True;User ID=sa;Password=***********";

            SqlConnection sqlConnection = new SqlConnection(myConnString);  //實例化連接對象
            sqlConnection.Open();

            string sql1 = "select 學號,密碼 from Student where 學號 = '" + username + "' and 密碼 = '" + password + "'";                                            //編寫SQL命令
            SqlCommand sqlCommand1 = new SqlCommand(sql1, sqlConnection);
            
            SqlDataReader sqlDataReader1 = sqlCommand1.ExecuteReader();
            if (sqlDataReader1.HasRows && textBox3.Text == code)
            {
                Class1.UserID = username;
                student_manage form2 = new student_manage();
                form2.Show();
                this.Hide();
            }
            sqlDataReader1.Close();


            string sql2 = "select 工號,密碼 from Manage where 工號 = '" + username + "' and 密碼 = '" + password + "'";
            SqlCommand sqlCommand2 = new SqlCommand(sql2, sqlConnection);
            SqlDataReader sqlDataReader2 = sqlCommand2.ExecuteReader();
            if (sqlDataReader2.HasRows && textBox3.Text == code)
            {
                Class1.UserID = username;
                manager_manage form3 = new manager_manage();
                form3.Show();
                this.Hide();
            }
            else
            {
                label6.Text = "登錄失敗,輸入密碼或驗證碼錯誤";
                textBox1.Text = "";
                textBox2.Text = "";
                textBox3.Text = "";
                return;
            }

            sqlDataReader2.Close();
            sqlConnection.Close();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            retrieve_password form3 = new retrieve_password();
            form3.Show();
            this.Hide();
        }
    }
}

找回密碼界面:
在這裏插入圖片描述

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 學生信息管理系統
{
    public partial class retrieve_password : Form
    {
        public retrieve_password()
        {
            InitializeComponent();
        }
        public string code;
        public static string EncryptWithMD5(string source)
        {
            byte[] sor = Encoding.UTF8.GetBytes(source);
            MD5 md5 = MD5.Create();
            byte[] result = md5.ComputeHash(sor);
            StringBuilder strbul = new StringBuilder(40);
            for (int i = 0; i < result.Length; i++)
            {
                strbul.Append(result[i].ToString("x2"));//加密結果"x2"結果爲32位,"x3"結果爲48位,"x4"結果爲64位
            }
            return strbul.ToString();
        }
        private void label6_Click(object sender, EventArgs e)
        {

        }

        private void label5_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            string username = textBox1.Text.Trim();  //取出賬號
            string cellphone = textBox2.Text.Trim();  //取出手機號碼
            int flag1 = 0;
            int flag2 = 0;

            string myConnString = "Data Source=.;Initial Catalog=student_information_management_system;Persist Security Info=True;User ID=sa;Password=**********";

            SqlConnection sqlConnection = new SqlConnection(myConnString);  //實例化連接對象
            sqlConnection.Open();

            string sql1 = "select 學號,手機號碼 from Student where 學號 = '" + username + "' and 手機號碼 = '" + cellphone + "'";                                            //編寫SQL命令
            SqlCommand sqlCommand1 = new SqlCommand(sql1, sqlConnection);

            SqlDataReader sqlDataReader1 = sqlCommand1.ExecuteReader();
            if (sqlDataReader1.HasRows )
            {
                if (textBox3.Text.Trim() != "")
                {
                    //使用regex(正則表達式)進行格式設置 至少有數字、大寫字母、小寫字母各一個。最少3個字符、最長20個字符。
                    Regex regex = new Regex(@"(?=.*[0-9]).{3,15}");

                    if (regex.IsMatch(textBox3.Text))//判斷格式是否符合要求
                    {
                        flag1 = 1;
                    }
                 
                }
            }
            sqlDataReader1.Close();
            if (flag1 == 1)
            {
                string password = EncryptWithMD5(textBox3.Text.Trim());
                string sql3 = "update Student set 密碼='" + password + "' where 學號='"+username+"'";
                SqlCommand sqlCommand3 = new SqlCommand(sql3, sqlConnection);
                SqlDataReader sqlDataReader3 = sqlCommand3.ExecuteReader();
                MessageBox.Show("修改成功");
                sqlDataReader3.Close();
                Form1 form1 = new Form1();
                form1.Show();
                this.Hide();
            }
            


            string sql2 = "select 工號,手機號碼 from Manage where 工號 = '" + username + "' and 手機號碼 = '" + cellphone + "'";
            SqlCommand sqlCommand2 = new SqlCommand(sql2, sqlConnection);
            SqlDataReader sqlDataReader2 = sqlCommand2.ExecuteReader();
            if (sqlDataReader2.HasRows)
            {
                if (textBox3.Text.Trim() != "")
                {
                    //使用regex(正則表達式)進行格式設置 至少有數字、大寫字母、小寫字母各一個。最少3個字符、最長20個字符。
                    Regex regex = new Regex(@"(?=.*[0-9]).{3,15}");

                    if (regex.IsMatch(textBox3.Text))//判斷格式是否符合要求
                    {
                        flag2 = 1;
                    }

                }
                sqlDataReader2.Close();
                if (flag2 == 1)
                {
                    string password = EncryptWithMD5(textBox3.Text.Trim());
                    string sql4 = "update Manage set 密碼='" + password + "' where 工號='" + username + "'";
                    SqlCommand sqlCommand4 = new SqlCommand(sql4, sqlConnection);
                    SqlDataReader sqlDataReader4 = sqlCommand4.ExecuteReader();
                    MessageBox.Show("修改成功");
                    sqlDataReader4.Close();
                    Form1 form1 = new Form1();
                    form1.Show();
                    this.Hide();
                }
            }
            else
            {
                label5.Text = "輸入密碼錯誤或手機號碼錯誤,請重新輸入";
                textBox1.Text = "";
                textBox2.Text = "";
                textBox3.Text = "";
                return;
            }
            sqlConnection.Close();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            Form1 form1 = new Form1();
            form1.Show();
            this.Hide();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
        }
    }
}

管理員功能界面:
在這裏插入圖片描述

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 學生信息管理系統
{
    public partial class manager_manage : Form
    {
        public string MyID;

        public manager_manage()
        {
            InitializeComponent();
        }

        private void manager_manage_Load(object sender, EventArgs e)
        {
            label1.Text = Class1.UserID+" 你好,歡迎進入系統";
            

            

        }

        private void button6_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            Form1 form1 = new Form1();
            form1.Show();
            this.Hide();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            manage_manager_information manage_manager_information1 = new manage_manager_information();
            manage_manager_information1.Show();
            this.Hide();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            manage_student_information manage_student_information1 = new manage_student_information();
            manage_student_information1.Show();
            this.Hide();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            manage_course manage_course1 = new manage_course();
            manage_course1.Show();
            this.Hide();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            manage_SCcs manage_SCcs1 = new manage_SCcs();
            manage_SCcs1.Show();
            this.Hide();
        }
    }
}

管理員管理管理員信息界面:
在這裏插入圖片描述

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 學生信息管理系統
{
    public partial class manage_manager_information : Form
    {
        SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=student_information_management_system;User ID=sa;Password=***********");
        public manage_manager_information()
        {
            InitializeComponent();
        }

        private void manage_manager_information_Load(object sender, EventArgs e)
        {
            // TODO: 這行代碼將數據加載到表“student_information_management_systemDataSet2.Manage”中。您可以根據需要移動或刪除它。
            this.manageTableAdapter.Fill(this.student_information_management_systemDataSet2.Manage);

        }
        public static string EncryptWithMD5(string source)
        {
            byte[] sor = Encoding.UTF8.GetBytes(source);
            MD5 md5 = MD5.Create();
            byte[] result = md5.ComputeHash(sor);
            StringBuilder strbul = new StringBuilder(40);
            for (int i = 0; i < result.Length; i++)
            {
                strbul.Append(result[i].ToString("x2"));//加密結果"x2"結果爲32位,"x3"結果爲48位,"x4"結果爲64位
            }
            return strbul.ToString();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void Close_Click_1(object sender, EventArgs e)
        {
            manager_manage manager_manage1 = new manager_manage();
            manager_manage1.Show();
            this.Hide();
        }

        private void Insert_Click_1(object sender, EventArgs e)
        {
            String Mno = textBox1.Text.Trim();
            String Mname = textBox2.Text.Trim();
            String Msex = textBox3.Text.Trim();
            String Mbirth = textBox4.Text.Trim();
            String Mnative = textBox5.Text.Trim();//籍貫
            String Mcelllphone = textBox6.Text.Trim();
            String Mnation = textBox7.Text.Trim();//民族
            String Mpassword = EncryptWithMD5(Mno);//密碼
            try
            {
                con.Open();
                string insertStr = "INSERT INTO Manage(工號,姓名,性別,出生日期,籍貫,手機號碼,民族,密碼) " +
                    "VALUES('" + Mno + "','" + Mname + "','" + Msex + "','" + Mbirth + "','" + Mnative +"','"+Mcelllphone + "','"+Mnation+"','"+ Mpassword + "')";
                SqlCommand cmd = new SqlCommand(insertStr, con);
                cmd.ExecuteNonQuery();
            }
            catch
            {
                MessageBox.Show("輸入數據違反要求");
            }
            finally
            {
                con.Dispose();
            }
            this.manageTableAdapter.Fill(this.student_information_management_systemDataSet2.Manage);
        }

        private void Delete_Click(object sender, EventArgs e)
        {
            try
            {
                con.Open();
                string select_id = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();//選擇的當前行第一列的值,也就是ID
                string delete_by_id = "delete from Manage where 工號=" + select_id;//sql刪除語句
                SqlCommand cmd = new SqlCommand(delete_by_id, con);
                cmd.ExecuteNonQuery();
            }
            catch
            {
                MessageBox.Show("請正確選擇行!");
            }
            finally
            {
                con.Dispose();
            }
            this.manageTableAdapter.Fill(this.student_information_management_systemDataSet2.Manage);
        }

        private void Update_Click(object sender, EventArgs e)
        {
            String Mno = textBox1.Text.Trim();
            String Mname = textBox2.Text.Trim();
            String Msex = textBox3.Text.Trim();
            String Mbirth = textBox4.Text.Trim();
            String Mnative = textBox5.Text.Trim();//籍貫
            String Mcelllphone = textBox6.Text.Trim();
            String Mnation = textBox7.Text.Trim();//民族
            try
            {
                con.Open();
                if (Mname != "")
                {
                    string insertStr = "UPDATE Manage SET 姓名 = '" + Mname + "' WHERE   工號='" + Mno + "'";
                    SqlCommand cmd = new SqlCommand(insertStr, con);
                    cmd.ExecuteNonQuery();
                }
                if (Msex != "")
                {
                    string insertStr = "UPDATE Manage SET 性別 = '" + Msex + "' WHERE   工號='" + Mno + "'";
                    SqlCommand cmd = new SqlCommand(insertStr, con);
                    cmd.ExecuteNonQuery();
                }
                if (Mbirth != "")
                {
                    string insertStr = "UPDATE Manage SET 出生日期 = '" + Mbirth + "' WHERE   工號='" + Mno + "'";
                    SqlCommand cmd = new SqlCommand(insertStr, con);
                    cmd.ExecuteNonQuery();
                }
                if (Mnative != "")
                {
                    string insertStr = "UPDATE Manage SET 籍貫 = '" + Mnative + "' WHERE   工號='" + Mno + "'";
                    SqlCommand cmd = new SqlCommand(insertStr, con);
                    cmd.ExecuteNonQuery();
                }
                if (Mcelllphone != "")
                {
                    string insertStr = "UPDATE Manage SET 手機號碼 = '" + Mcelllphone + "' WHERE   工號='" + Mno + "'";
                    SqlCommand cmd = new SqlCommand(insertStr, con);
                    cmd.ExecuteNonQuery();
                }
                if (Mnation != "")
                {
                    string insertStr = "UPDATE Manage SET 民族 = '" + Mnation + "' WHERE   工號='" + Mno + "'";
                    SqlCommand cmd = new SqlCommand(insertStr, con);
                    cmd.ExecuteNonQuery();
                }
            }
            catch
            {
                MessageBox.Show("輸入數據違反要求!");
            }
            finally
            {
                con.Dispose();
            }
            this.manageTableAdapter.Fill(this.student_information_management_systemDataSet2.Manage);
        }

        private void Select_Click(object sender, EventArgs e)
        {
            String Mno = textBox1.Text.Trim();
            String Mname = textBox2.Text.Trim();
            String Msex = textBox3.Text.Trim();
            String Mbirth = textBox4.Text.Trim();
            String Mnative = textBox5.Text.Trim();//籍貫
            String Mcelllphone = textBox6.Text.Trim();
            String Mnation = textBox7.Text.Trim();//民族
            
            String conn = "Data Source=.;Initial Catalog=student_information_management_system;User ID=sa;Password=********";
            SqlConnection sqlConnection = new SqlConnection(conn);
            try
            {
                if (Mno != "")
                {
                    sqlConnection.Open();
                    String select_by_id = "select * from Manage where 工號='" + Mno + "'";
                    SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    BindingSource bindingSource = new BindingSource();
                    bindingSource.DataSource = sqlDataReader;
                    dataGridView1.DataSource = bindingSource;
                }
                if (Mname != "")
                {
                    sqlConnection.Open();
                    String select_by_id = "select * from Manage where 姓名 Like'" + Mname + "%'";
                    SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    BindingSource bindingSource = new BindingSource();
                    bindingSource.DataSource = sqlDataReader;
                    dataGridView1.DataSource = bindingSource;
                }
                if (Msex != "")
                {
                    sqlConnection.Open();
                    String select_by_id = "select * from Manage where 性別='" + Msex + "'";
                    SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    BindingSource bindingSource = new BindingSource();
                    bindingSource.DataSource = sqlDataReader;
                    dataGridView1.DataSource = bindingSource;
                }
                if (Mbirth != "")
                {
                    sqlConnection.Open();
                    String select_by_id = "select * from Manage where 出生日期 Like'" + Mbirth + "%'";
                    SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    BindingSource bindingSource = new BindingSource();
                    bindingSource.DataSource = sqlDataReader;
                    dataGridView1.DataSource = bindingSource;
                }
                if (Mnative != "")
                {
                    sqlConnection.Open();
                    String select_by_id = "select * from Manage where 籍貫 Like'" + Mnative + "%'";
                    SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    BindingSource bindingSource = new BindingSource();
                    bindingSource.DataSource = sqlDataReader;
                    dataGridView1.DataSource = bindingSource;
                }
                if (Mcelllphone != "")
                {
                    sqlConnection.Open();
                    String select_by_id = "select * from Manage where 手機號碼='" + Mcelllphone + "'";
                    SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    BindingSource bindingSource = new BindingSource();
                    bindingSource.DataSource = sqlDataReader;
                    dataGridView1.DataSource = bindingSource;
                }
                if (Mnation != "")
                {
                    sqlConnection.Open();
                    String select_by_id = "select * from Manage where 民族 Like'" + Mnation + "%'";
                    SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    BindingSource bindingSource = new BindingSource();
                    bindingSource.DataSource = sqlDataReader;
                    dataGridView1.DataSource = bindingSource;
                }

            }
            catch
            {
                MessageBox.Show("查詢語句有誤!");
            }
            finally
            {
                sqlConnection.Close();
            }
        }
    }
}

管理員管理學生信息界面:
在這裏插入圖片描述

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 學生信息管理系統
{
    public partial class manage_student_information : Form
    {
        SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=student_information_management_system;User ID=sa;Password=***********");
        public manage_student_information()
        {
            InitializeComponent();
        }
        public static string EncryptWithMD5(string source)
        {
            byte[] sor = Encoding.UTF8.GetBytes(source);
            MD5 md5 = MD5.Create();
            byte[] result = md5.ComputeHash(sor);
            StringBuilder strbul = new StringBuilder(40);
            for (int i = 0; i < result.Length; i++)
            {
                strbul.Append(result[i].ToString("x2"));//加密結果"x2"結果爲32位,"x3"結果爲48位,"x4"結果爲64位
            }
            return strbul.ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void Close_Click(object sender, EventArgs e)
        {
            manager_manage manager_manage1 = new manager_manage();
            manager_manage1.Show();
            this.Hide();
        }

        private void Insert_Click(object sender, EventArgs e)
        {
            String Mno = textBox1.Text.Trim();
            String Mname = textBox2.Text.Trim();
            String Msex = textBox3.Text.Trim();
            String Mbirth = textBox4.Text.Trim();
            String Mnative = textBox5.Text.Trim();//籍貫
            String Mcelllphone = textBox6.Text.Trim();
            String Mnation = textBox7.Text.Trim();//民族
            String Mgrade = textBox8.Text.Trim();
            String Mdept = textBox9.Text.Trim();
            String Mpassword = EncryptWithMD5(Mno);//密碼
            try
            {
                con.Open();
                string insertStr = "INSERT INTO Student(學號,姓名,性別,出生日期,籍貫,手機號碼,民族,年級,專業,密碼) " +
                    "VALUES('" + Mno + "','" + Mname + "','" + Msex + "','" + Mbirth + "','" + Mnative + "','" + Mcelllphone + "','" + Mnation + "','" + Mgrade + "','" + Mdept + "','" + Mpassword + "')";
                SqlCommand cmd = new SqlCommand(insertStr, con);
                cmd.ExecuteNonQuery();
            }
            catch
            {
                MessageBox.Show("輸入數據違反要求");
            }
            finally
            {
                con.Dispose();
            }
            this.studentTableAdapter.Fill(this.student_information_management_systemDataSet3.Student);
        }

        private void manage_student_information_Load(object sender, EventArgs e)
        {
            // TODO: 這行代碼將數據加載到表“student_information_management_systemDataSet3.Student”中。您可以根據需要移動或刪除它。
            this.studentTableAdapter.Fill(this.student_information_management_systemDataSet3.Student);

        }

        private void Delete_Click(object sender, EventArgs e)
        {
            try
            {
                con.Open();
                string select_id = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();//選擇的當前行第一列的值,也就是ID
                string delete_by_id = "delete from Student where 學號=" + select_id;//sql刪除語句
                SqlCommand cmd = new SqlCommand(delete_by_id, con);
                cmd.ExecuteNonQuery();
            }
            catch
            {
                MessageBox.Show("請正確選擇行!");
            }
            finally
            {
                con.Dispose();
            }
            this.studentTableAdapter.Fill(this.student_information_management_systemDataSet3.Student);
        }

        private void Update_Click(object sender, EventArgs e)
        {
            String Mno = textBox1.Text.Trim();
            String Mname = textBox2.Text.Trim();
            String Msex = textBox3.Text.Trim();
            String Mbirth = textBox4.Text.Trim();
            String Mnative = textBox5.Text.Trim();//籍貫
            String Mcelllphone = textBox6.Text.Trim();
            String Mnation = textBox7.Text.Trim();//民族
            String Mgrade = textBox8.Text.Trim();
            String Mdept = textBox9.Text.Trim();
            try
            {
                con.Open();
                if (Mname != "")
                {
                    string insertStr = "UPDATE Student SET 姓名 = '" + Mname + "' WHERE   學號='" + Mno + "'";
                    SqlCommand cmd = new SqlCommand(insertStr, con);
                    cmd.ExecuteNonQuery();
                }
                if (Msex != "")
                {
                    string insertStr = "UPDATE Student SET 性別 = '" + Msex + "' WHERE   學號='" + Mno + "'";
                    SqlCommand cmd = new SqlCommand(insertStr, con);
                    cmd.ExecuteNonQuery();
                }
                if (Mbirth != "")
                {
                    string insertStr = "UPDATE Student SET 出生日期 = '" + Mbirth + "' WHERE   學號='" + Mno + "'";
                    SqlCommand cmd = new SqlCommand(insertStr, con);
                    cmd.ExecuteNonQuery();
                }
                if (Mnative != "")
                {
                    string insertStr = "UPDATE Student SET 籍貫 = '" + Mnative + "' WHERE   學號='" + Mno + "'";
                    SqlCommand cmd = new SqlCommand(insertStr, con);
                    cmd.ExecuteNonQuery();
                }
                if (Mcelllphone != "")
                {
                    string insertStr = "UPDATE Student SET 手機號碼 = '" + Mcelllphone + "' WHERE   學號='" + Mno + "'";
                    SqlCommand cmd = new SqlCommand(insertStr, con);
                    cmd.ExecuteNonQuery();
                }
                if (Mnation != "")
                {
                    string insertStr = "UPDATE Student SET 民族 = '" + Mnation + "' WHERE   學號='" + Mno + "'";
                    SqlCommand cmd = new SqlCommand(insertStr, con);
                    cmd.ExecuteNonQuery();
                }
                if (Mgrade != "")
                {
                    string insertStr = "UPDATE Student SET 年級 = '" + Mgrade + "' WHERE   學號='" + Mno + "'";
                    SqlCommand cmd = new SqlCommand(insertStr, con);
                    cmd.ExecuteNonQuery();
                }
                if (Mdept != "")
                {
                    string insertStr = "UPDATE Student SET 專業 = '" + Mdept + "' WHERE   學號='" + Mno + "'";
                    SqlCommand cmd = new SqlCommand(insertStr, con);
                    cmd.ExecuteNonQuery();
                }
            }
            catch
            {
                MessageBox.Show("輸入數據違反要求!");
            }
            finally
            {
                con.Dispose();
            }
            this.studentTableAdapter.Fill(this.student_information_management_systemDataSet3.Student);
        }

        private void Select_Click(object sender, EventArgs e)
        {
            String Mno = textBox1.Text.Trim();
            String Mname = textBox2.Text.Trim();
            String Msex = textBox3.Text.Trim();
            String Mbirth = textBox4.Text.Trim();
            String Mnative = textBox5.Text.Trim();//籍貫
            String Mcelllphone = textBox6.Text.Trim();
            String Mnation = textBox7.Text.Trim();//民族
            String Mgrade = textBox8.Text.Trim();
            String Mdept = textBox9.Text.Trim();
            String conn = "Data Source=.;Initial Catalog=student_information_management_system;User ID=sa;Password=***********";
            SqlConnection sqlConnection = new SqlConnection(conn);
            try
            {
                if (Mno != "")
                {
                    sqlConnection.Open();
                    String select_by_id = "select * from Manage where 工號='" + Mno + "'";
                    SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    BindingSource bindingSource = new BindingSource();
                    bindingSource.DataSource = sqlDataReader;
                    dataGridView1.DataSource = bindingSource;
                }
                if (Mname != "")
                {
                    sqlConnection.Open();
                    String select_by_id = "select * from Student where 姓名 Like'" + Mname + "%'";
                    SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    BindingSource bindingSource = new BindingSource();
                    bindingSource.DataSource = sqlDataReader;
                    dataGridView1.DataSource = bindingSource;
                }
                if (Msex != "")
                {
                    sqlConnection.Open();
                    String select_by_id = "select * from Student where 性別='" + Msex + "'";
                    SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    BindingSource bindingSource = new BindingSource();
                    bindingSource.DataSource = sqlDataReader;
                    dataGridView1.DataSource = bindingSource;
                }
                if (Mbirth != "")
                {
                    sqlConnection.Open();
                    String select_by_id = "select * from Student where 出生日期 Like'" + Mbirth + "'";
                    SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    BindingSource bindingSource = new BindingSource();
                    bindingSource.DataSource = sqlDataReader;
                    dataGridView1.DataSource = bindingSource;
                }
                if (Mnative != "")
                {
                    sqlConnection.Open();
                    String select_by_id = "select * from Student where 籍貫 Like'" + Mnative + "'";
                    SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    BindingSource bindingSource = new BindingSource();
                    bindingSource.DataSource = sqlDataReader;
                    dataGridView1.DataSource = bindingSource;
                }
                if (Mcelllphone != "")
                {
                    sqlConnection.Open();
                    String select_by_id = "select * from Student where 手機號碼='" + Mcelllphone + "'";
                    SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    BindingSource bindingSource = new BindingSource();
                    bindingSource.DataSource = sqlDataReader;
                    dataGridView1.DataSource = bindingSource;
                }
                if (Mnation != "")
                {
                    sqlConnection.Open();
                    String select_by_id = "select * from Student where 民族 Like'" + Mnation + "'";
                    SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    BindingSource bindingSource = new BindingSource();
                    bindingSource.DataSource = sqlDataReader;
                    dataGridView1.DataSource = bindingSource;
                }
                if (Mgrade != "")
                {
                    sqlConnection.Open();
                    String select_by_id = "select * from Student where 年級='" + Mgrade + "'";
                    SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    BindingSource bindingSource = new BindingSource();
                    bindingSource.DataSource = sqlDataReader;
                    dataGridView1.DataSource = bindingSource;
                }
                if (Mdept != "")
                {
                    sqlConnection.Open();
                    String select_by_id = "select * from Student where 專業 Like'" + Mdept + "%'";
                    SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    BindingSource bindingSource = new BindingSource();
                    bindingSource.DataSource = sqlDataReader;
                    dataGridView1.DataSource = bindingSource;
                }

            }
            catch
            {
                MessageBox.Show("查詢語句有誤!");
            }
            finally
            {
                sqlConnection.Close();
            }
        }
    }
}

管理員管理課程界面:
在這裏插入圖片描述

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 學生信息管理系統
{
    public partial class manage_course : Form
    {
        SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=student_information_management_system;User ID=sa;Password=**********");
        public manage_course()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void Close_Click(object sender, EventArgs e)
        {
            manager_manage manager_manage1 = new manager_manage();
            manager_manage1.Show();
            this.Hide();
        }

        private void Insert_Click(object sender, EventArgs e)
        {
            String Cno = textBox1.Text.Trim();//課程號
            String Cname = textBox2.Text.Trim();//課程名
            String Credit = textBox3.Text.Trim();//學分
            String Cplace = textBox4.Text.Trim();//上課地點
            String Ctime = textBox5.Text.Trim();//上課時間
            try
            {
                con.Open();
                string insertStr = "INSERT INTO Course(課程號,課程名,學分,上課地點,上課時間) " +
                    "VALUES('" + Cno + "','" + Cname + "','" + Credit + "','" + Cplace + "','" + Ctime + "')";
                SqlCommand cmd = new SqlCommand(insertStr, con);
                cmd.ExecuteNonQuery();
            }
            catch
            {
                MessageBox.Show("輸入數據違反要求");
            }
            finally
            {
                con.Dispose();
            }
            this.courseTableAdapter.Fill(this.student_information_management_systemDataSet4.Course);
        }

        private void manage_course_Load(object sender, EventArgs e)
        {
            // TODO: 這行代碼將數據加載到表“student_information_management_systemDataSet4.Course”中。您可以根據需要移動或刪除它。
            this.courseTableAdapter.Fill(this.student_information_management_systemDataSet4.Course);

        }

        private void Delete_Click(object sender, EventArgs e)
        {
            try
            {
                con.Open();
                string select_id = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();//選擇的當前行第一列的值,也就是ID
                string delete_by_id = "delete from Course where 課程號=" + select_id;//sql刪除語句
                SqlCommand cmd = new SqlCommand(delete_by_id, con);
                cmd.ExecuteNonQuery();
            }
            catch
            {
                MessageBox.Show("請正確選擇行!");
            }
            finally
            {
                con.Dispose();
            }
            this.courseTableAdapter.Fill(this.student_information_management_systemDataSet4.Course);
        }

        private void Update_Click(object sender, EventArgs e)
        {
            String Cno = textBox1.Text.Trim();//課程號
            String Cname = textBox2.Text.Trim();//課程名
            String Credit = textBox3.Text.Trim();//學分
            String Cplace = textBox4.Text.Trim();//上課地點
            String Ctime = textBox5.Text.Trim();//上課時間
            try
            {
                con.Open();
                if (Cname != "")
                {
                    string insertStr = "UPDATE Course SET 課程名 = '" + Cname + "' WHERE   課程號='" + Cno + "'";
                    SqlCommand cmd = new SqlCommand(insertStr, con);
                    cmd.ExecuteNonQuery();
                }
                if (Credit != "")
                {
                    string insertStr = "UPDATE Course SET 學分 = '" + Credit + "' WHERE   課程號='" + Cno + "'";
                    SqlCommand cmd = new SqlCommand(insertStr, con);
                    cmd.ExecuteNonQuery();
                }
                if (Cplace != "")
                {
                    string insertStr = "UPDATE Course SET 上課地點 = '" + Cplace + "' WHERE   課程號='" + Cno + "'";
                    SqlCommand cmd = new SqlCommand(insertStr, con);
                    cmd.ExecuteNonQuery();
                }
                if (Ctime != "")
                {
                    string insertStr = "UPDATE Course SET 上課時間 = '" + Ctime + "' WHERE   課程號='" + Cno + "'";
                    SqlCommand cmd = new SqlCommand(insertStr, con);
                    cmd.ExecuteNonQuery();
                }
            }
            catch
            {
                MessageBox.Show("輸入數據違反要求!");
            }
            finally
            {
                con.Dispose();
            }
            this.courseTableAdapter.Fill(this.student_information_management_systemDataSet4.Course);
        }

        private void Select_Click(object sender, EventArgs e)
        {
            String Cno = textBox1.Text.Trim();//課程號
            String Cname = textBox2.Text.Trim();//課程名
            String Credit = textBox3.Text.Trim();//學分
            String Cplace = textBox4.Text.Trim();//上課地點
            String Ctime = textBox5.Text.Trim();//上課時間
            String conn = "Data Source=.;Initial Catalog=student_information_management_system;User ID=sa;Password=********";
            SqlConnection sqlConnection = new SqlConnection(conn);
            try
            {
                if (Cno != "")
                {
                    sqlConnection.Open();
                    String select_by_id = "select * from Course where 課程號='" + Cno + "'";
                    SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    BindingSource bindingSource = new BindingSource();
                    bindingSource.DataSource = sqlDataReader;
                    dataGridView1.DataSource = bindingSource;
                }
                if (Cname != "")
                {
                    sqlConnection.Open();
                    String select_by_id = "select * from Course where 課程名 Like'" + Cname + "%'";
                    SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    BindingSource bindingSource = new BindingSource();
                    bindingSource.DataSource = sqlDataReader;
                    dataGridView1.DataSource = bindingSource;
                }
                if (Credit != "")
                {
                    sqlConnection.Open();
                    String select_by_id = "select * from Course where 學分='" + Credit + "'";
                    SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    BindingSource bindingSource = new BindingSource();
                    bindingSource.DataSource = sqlDataReader;
                    dataGridView1.DataSource = bindingSource;
                }
                if (Cplace != "")
                {
                    sqlConnection.Open();
                    String select_by_id = "select * from Course where 上課地點 Like'" + Cplace + "%'";
                    SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    BindingSource bindingSource = new BindingSource();
                    bindingSource.DataSource = sqlDataReader;
                    dataGridView1.DataSource = bindingSource;
                }
                if (Ctime != "")
                {
                    sqlConnection.Open();
                    String select_by_id = "select * from Course where 上課時間 Like'" + Ctime + "%'";
                    SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    BindingSource bindingSource = new BindingSource();
                    bindingSource.DataSource = sqlDataReader;
                    dataGridView1.DataSource = bindingSource;
                }
            }
            catch
            {
                MessageBox.Show("查詢語句有誤!");
            }
            finally
            {
                sqlConnection.Close();
            }
        }
    }
}

管理員管理成績界面:

在這裏插入圖片描述

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 學生信息管理系統
{
    public partial class manage_SCcs : Form
    {
        SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=student_information_management_system;User ID=sa;Password=*********");
        public manage_SCcs()
        {
            InitializeComponent();
        }

        private void manage_SCcs_Load(object sender, EventArgs e)
        {
            // TODO: 這行代碼將數據加載到表“student_information_management_systemDataSet12.SC”中。您可以根據需要移動或刪除它。
            this.sCTableAdapter1.Fill(this.student_information_management_systemDataSet12.SC);
            // TODO: 這行代碼將數據加載到表“student_information_management_systemDataSet5.SC”中。您可以根據需要移動或刪除它。
            //this.sCTableAdapter.Fill(this.student_information_management_systemDataSet5.SC);

        }

        private void button1_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void Close_Click(object sender, EventArgs e)
        {
            manager_manage manager_manage1 = new manager_manage();
            manager_manage1.Show();
            this.Hide();
        }

        private void Insert_Click(object sender, EventArgs e)
        {

            String Sno = textBox1.Text.Trim();
            String Sname = textBox2.Text.Trim();
            String Cno = textBox3.Text.Trim();
            String Cname = textBox4.Text.Trim();
            String Grade = textBox5.Text.Trim();
            String Credit = textBox6.Text.Trim();

            try
            {
                con.Open();
                if(Grade!="" && Credit != "")
                {
                    string insertStr = "INSERT INTO SC(學號,姓名,課程號,課程名,成績,學分) " +
                    "VALUES('" + Sno + "','" + Sname + "','" + Cno + "','" + Cname + "'," + Grade + "," + Credit + ")";
                    SqlCommand cmd = new SqlCommand(insertStr, con);
                    cmd.ExecuteNonQuery();
                }
            }
            catch
            {
                MessageBox.Show("輸入數據違反要求");
            }
            finally
            {
                con.Dispose();
            }
            this.sCTableAdapter1.Fill(this.student_information_management_systemDataSet12.SC);
        }

        private void Delete_Click(object sender, EventArgs e)
        {
            try
            {
                con.Open();
                string select_id1 = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();//選擇的當前行第一列的值,也就是ID
                string select_id2 = dataGridView1.SelectedRows[0].Cells[2].Value.ToString().Trim();
                string delete_by_id = "delete from SC where 學號='" + select_id1+ "' AND 課程號='"+select_id2+ "'";//sql刪除語句
                SqlCommand cmd = new SqlCommand(delete_by_id, con);
                cmd.ExecuteNonQuery();
            }
            catch
            {
                MessageBox.Show("請正確選擇行!");
            }
            finally
            {
                con.Dispose();
            }
            this.sCTableAdapter1.Fill(this.student_information_management_systemDataSet12.SC);
        }

        private void Update_Click(object sender, EventArgs e)
        {
            String Sno = textBox1.Text.Trim();
            String Cno = textBox3.Text.Trim();
            String Grade = textBox5.Text.Trim();
            try
            {
                con.Open();
                    string insertStr = "UPDATE SC SET 成績 = " + Grade + " WHERE   學號='" + Sno + "' AND 課程號='"+ Cno + "'";
                    SqlCommand cmd = new SqlCommand(insertStr, con);
                    cmd.ExecuteNonQuery();
            }
            catch
            {
                MessageBox.Show("輸入數據違反要求!");
            }
            finally
            {
                con.Dispose();
            }
            this.sCTableAdapter1.Fill(this.student_information_management_systemDataSet12.SC);
        }

        private void Select_Click(object sender, EventArgs e)
        {
            String Sno = textBox1.Text.Trim();
            String Sname = textBox2.Text.Trim();
            String Cno = textBox3.Text.Trim();
            String Cname = textBox4.Text.Trim();
            String  Grade =textBox5.Text.Trim();
            String Credit = textBox6.Text.Trim();
            String conn = "Data Source=.;Initial Catalog=student_information_management_system;User ID=sa;Password=********";
            SqlConnection sqlConnection = new SqlConnection(conn);
            try
            {
                if (Sno != "")
                {
                    sqlConnection.Open();
                    String select_by_id = "select * from SC where 學號='" + Sno + "'";
                    SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    BindingSource bindingSource = new BindingSource();
                    bindingSource.DataSource = sqlDataReader;
                    dataGridView1.DataSource = bindingSource;
                }
                if (Sname != "")
                {
                    sqlConnection.Open();
                    String select_by_id = "select * from SC where 姓名 Like'" + Sname + "%'";
                    SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    BindingSource bindingSource = new BindingSource();
                    bindingSource.DataSource = sqlDataReader;
                    dataGridView1.DataSource = bindingSource;
                }
                if (Cno != "")
                {
                    sqlConnection.Open();
                    String select_by_id = "select * from SC where 課程號='" + Cno + "'";
                    SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    BindingSource bindingSource = new BindingSource();
                    bindingSource.DataSource = sqlDataReader;
                    dataGridView1.DataSource = bindingSource;
                }
                if (Cname != "")
                {
                    sqlConnection.Open();
                    String select_by_id = "select * from SC where 課程名 Like'" + Cname + "%'";
                    SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    BindingSource bindingSource = new BindingSource();
                    bindingSource.DataSource = sqlDataReader;
                    dataGridView1.DataSource = bindingSource;
                }
                if (Grade != "")
                {
                    sqlConnection.Open();
                    String select_by_id = "select * from SC where 成績 =" + Grade ;
                    SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    BindingSource bindingSource = new BindingSource();
                    bindingSource.DataSource = sqlDataReader;
                    dataGridView1.DataSource = bindingSource;
                }
                if (Credit != "")
                {
                    sqlConnection.Open();
                    String select_by_id = "select * from SC where 學分=" + Credit;
                    SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    BindingSource bindingSource = new BindingSource();
                    bindingSource.DataSource = sqlDataReader;
                    dataGridView1.DataSource = bindingSource;
                }
              

            }
            catch
            {
                MessageBox.Show("查詢語句有誤!");
            }
            finally
            {
                sqlConnection.Close();
            }
        }
    }
}

學生功能界面:
在這裏插入圖片描述

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;

namespace 學生信息管理系統
{
    public partial class student_manage : Form
    {
        public student_manage()
        {
            InitializeComponent();
        }

        private void student_manage_Load(object sender, EventArgs e)
        {
            label1.Text = Class1.UserID + " 你好,歡迎進入系統";
        }

        private void button5_Click(object sender, EventArgs e)
        {
            Form1 form1 = new Form1();
            form1.Show();
            this.Hide();
        }

        private void button6_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            student_SC student_SC1 = new student_SC();
            student_SC1.Show();
            this.Hide();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            student_course student_course1 = new student_course();
            student_course1.Show();
            this.Hide();
        }
    }
}

學生查詢成績界面:
在這裏插入圖片描述

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 學生信息管理系統
{
    public partial class student_SC : Form
    {
        SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=student_information_management_system;User ID=sa;Password=************");
        public student_SC()
        {
            InitializeComponent();
        }

        private void student_SC_Load(object sender, EventArgs e)
        {
            // TODO: 這行代碼將數據加載到表“student_information_management_systemDataSet11.SC”中。您可以根據需要移動或刪除它。
            this.sCTableAdapter1.Fill(this.student_information_management_systemDataSet11.SC);
            // TODO: 這行代碼將數據加載到表“student_information_management_systemDataSet7.SC”中。您可以根據需要移動或刪除它。
            this.sCTableAdapter.Fill(this.student_information_management_systemDataSet7.SC);
            String Sno = Class1.UserID;
            String conn = "Data Source=.;Initial Catalog=student_information_management_system;User ID=sa;Password=**************";
            SqlConnection sqlConnection = new SqlConnection(conn);
            try
            {
                sqlConnection.Open();
                String select_by_id = "select * from SC where 學號='" + Sno + "'";
                SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                BindingSource bindingSource = new BindingSource();
                bindingSource.DataSource = sqlDataReader;
                dataGridView1.DataSource = bindingSource;
            }
            catch
            {

            }
            finally
            {
                sqlConnection.Close();
            }
        }

        private void Close_Click(object sender, EventArgs e)
        {
            student_manage student_manage1 = new student_manage();
            student_manage1.Show();
            this.Hide();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            String conn = "Data Source=.;Initial Catalog=student_information_management_system;User ID=sa;Password=****************";
            SqlConnection sqlConnection = new SqlConnection(conn);
            String str = Class1.UserID;
            try
            {
                sqlConnection.Open();
                String select_by_id = "select * from SC where 成績<60 AND 學號='" + str + "'";
                SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                BindingSource bindingSource = new BindingSource();
                bindingSource.DataSource = sqlDataReader;
                dataGridView1.DataSource = bindingSource;
            }
            catch
            {
                MessageBox.Show("查詢語句有誤!");
            }
            finally
            {
                sqlConnection.Close();
            }
        }

        private void Select_Click(object sender, EventArgs e)
        {

            String Cno = textBox1.Text.Trim();
            String Cname = textBox2.Text.Trim();
            String str = Class1.UserID;
            String conn = "Data Source=.;Initial Catalog=student_information_management_system;User ID=sa;Password=****************";
            SqlConnection sqlConnection = new SqlConnection(conn);
            try
            {
                if (Cno != "")
                {
                    sqlConnection.Open();
                    String select_by_id = "select * from SC where 學號='" + str + "'AND 課程號='"+Cno+"'";
                    SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    BindingSource bindingSource = new BindingSource();
                    bindingSource.DataSource = sqlDataReader;
                    dataGridView1.DataSource = bindingSource;
                }
                if (Cname != "")
                {
                    sqlConnection.Open();
                    String select_by_id = "select * from SC where 學號='" + str + "'AND 課程名 Like'" + Cname + "%'";
                    SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    BindingSource bindingSource = new BindingSource();
                    bindingSource.DataSource = sqlDataReader;
                    dataGridView1.DataSource = bindingSource;
                }

            }
            catch
            {
                MessageBox.Show("查詢語句有誤!");
            }
            finally
            {
                sqlConnection.Close();
            }
        }
    }
}

學生選擇課程、查詢課程界面:
在這裏插入圖片描述

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 學生信息管理系統
{
    public partial class student_course : Form
    {
        SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=student_information_management_system;User ID=sa;Password=***********");
        public student_course()
        {
            InitializeComponent();
        }

        private void student_course_Load(object sender, EventArgs e)
        {
            // TODO: 這行代碼將數據加載到表“student_information_management_systemDataSet10.SC”中。您可以根據需要移動或刪除它。
            this.sCTableAdapter1.Fill(this.student_information_management_systemDataSet10.SC);
            // TODO: 這行代碼將數據加載到表“student_information_management_systemDataSet9.SC”中。您可以根據需要移動或刪除它。
            this.sCTableAdapter.Fill(this.student_information_management_systemDataSet9.SC);
            // TODO: 這行代碼將數據加載到表“student_information_management_systemDataSet8.Course”中。您可以根據需要移動或刪除它。
            this.courseTableAdapter.Fill(this.student_information_management_systemDataSet8.Course);
            String Sno = Class1.UserID;
            String conn = "Data Source=.;Initial Catalog=student_information_management_system;User ID=sa;Password=**********";
            SqlConnection sqlConnection = new SqlConnection(conn);
            try
            {
                sqlConnection.Open();
                String select_by_id = "select * from SC where 學號='" + Sno + "'";
                SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                BindingSource bindingSource = new BindingSource();
                bindingSource.DataSource = sqlDataReader;
                dataGridView2.DataSource = bindingSource;
            }
            catch
            {

            }
            finally
            {
                sqlConnection.Close();
            }
        }

        private void Select_Click(object sender, EventArgs e)
        {
            String Cno = textBox1.Text.Trim();//課程號
            String Cname = textBox2.Text.Trim();//課程名
            String Credit = textBox3.Text.Trim();//學分
            String Cplace = textBox4.Text.Trim();//上課地點
            String Ctime = textBox5.Text.Trim();//上課時間
            String conn = "Data Source=.;Initial Catalog=student_information_management_system;User ID=sa;Password=**********";
            SqlConnection sqlConnection = new SqlConnection(conn);
            try
            {
                if (Cno != "")
                {
                    sqlConnection.Open();
                    String select_by_id = "select * from Course where 課程號='" + Cno + "'";
                    SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    BindingSource bindingSource = new BindingSource();
                    bindingSource.DataSource = sqlDataReader;
                    dataGridView1.DataSource = bindingSource;
                }
                if (Cname != "")
                {
                    sqlConnection.Open();
                    String select_by_id = "select * from Course where 課程名 Like'" + Cname + "%'";
                    SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    BindingSource bindingSource = new BindingSource();
                    bindingSource.DataSource = sqlDataReader;
                    dataGridView1.DataSource = bindingSource;
                }
                if (Credit != "")
                {
                    sqlConnection.Open();
                    String select_by_id = "select * from Course where 學分='" + Credit + "'";
                    SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    BindingSource bindingSource = new BindingSource();
                    bindingSource.DataSource = sqlDataReader;
                    dataGridView1.DataSource = bindingSource;
                }
                if (Cplace != "")
                {
                    sqlConnection.Open();
                    String select_by_id = "select * from Course where 上課地點 Like'" + Cplace + "%'";
                    SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    BindingSource bindingSource = new BindingSource();
                    bindingSource.DataSource = sqlDataReader;
                    dataGridView1.DataSource = bindingSource;
                }
                if (Ctime != "")
                {
                    sqlConnection.Open();
                    String select_by_id = "select * from Course where 上課時間 Like'" + Ctime + "%'";
                    SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    BindingSource bindingSource = new BindingSource();
                    bindingSource.DataSource = sqlDataReader;
                    dataGridView1.DataSource = bindingSource;
                }

            }
            catch
            {
                MessageBox.Show("查詢語句有誤!");
            }
            finally
            {
                sqlConnection.Close();
            }
        }

        private void Close_Click(object sender, EventArgs e)
        {
            student_manage student_manage1 = new student_manage();
            student_manage1.Show();
            this.Hide();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void Insert_Click(object sender, EventArgs e)
        {
            String Cno = textBox1.Text.Trim();//課程號
            String Cname = textBox2.Text.Trim();//課程名
            String Sno = Class1.UserID;//學號
            try
            {
                con.Open();
                string insertStr = "INSERT INTO SC(課程號,課程名,學號) " +
                    "VALUES('" + Cno + "','" + Cname + "','" + Sno + "')";
                SqlCommand cmd = new SqlCommand(insertStr, con);
                cmd.ExecuteNonQuery();
            }
            catch
            {
                MessageBox.Show("輸入數據違反要求");
            }
            finally
            {
                con.Dispose();
            }
            this.sCTableAdapter.Fill(this.student_information_management_systemDataSet9.SC);
            /*this.sCTableAdapter1.Fill(this.student_information_management_systemDataSet10.SC);*/
        }
    }
}

實驗效果講解視頻鏈接:

【2019-2020春學期】數據庫實驗大作業——學生信息管理系統功能講解

心得:

終於完成大作業啦,開心
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章