C#編寫簡易的學生成績查詢

来源:http://www.cnblogs.com/qufeiba/archive/2017/06/20/7056840.html
-Advertisement-
Play Games

C#編寫簡易的學生成績查詢 什麼是學生成績查詢系統? 使用C#語言編寫的一個可安裝的簡單CS系統,實現了用戶登錄,學生信息添加,成績修改,刪除,查詢等功能 開發環境 開發環境 visual studio2010(新版本2015,2017也可) visual studio2010(sql2008資料庫 ...


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);

 

            SqlDataReader reader = cmd.ExecuteReader();

            this.dataGridView1.DataSource = reader;

            //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圖

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 我們使用資料庫的時候,如果查詢條件太複雜,則會涉及到很多問題 1、無法維護,各種嵌套查詢,各種複雜的查詢,想要優化都無從下手 2、效率低下,一般語句複雜了之後,比如使用or,like %,,%查詢之後資料庫的索引就沒有辦法利用到了,這個時候的搜索就會全表掃描,數據量少的時候可能性能還能接受,但是數據 ...
  • 1.安裝好jdk。 2.打開終端。 3.sudo到root帳戶,輸入 vi /etc/profile ,打開全局配置文件。 4.在profile中添加如下配置 JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/ ...
  • 在編程或是整理知識的時候一直苦於沒有一款可以幫助理清思路的工具。 在網上苦尋良久,終於找到了一款可心可意的小軟體 —— Graphviz。 折騰了一番,終於可以湊合著用了。 現將折騰的成果記錄於此以作備忘,當然如果能夠拋磚引玉那就再好不過了。 因為本人主要使用 Windows 以下將用 Window ...
  • ubuntn預設下載路徑的源是國外的下載很慢換成國內的下載路徑會好很多 在ubuntu應用搜索框(左上腳那個)中輸入software 1.software&Updates 應用點擊software 2.在彈出的界面中的download中選擇other 3.在之後彈出的框中選到china 4.在裡面選 ...
  • Shell腳本,就是利用Shell的命令解釋的功能,對一個純文本的文件進行解析,然後執行這些功能,也可以說Shell腳本就是一系列命令的集合。Shell可以直接使用在win/Unix/Linux上面,並且可以調用大量系統內部的功能來解釋執行程式,如果熟練掌握Shell腳本,可以讓我們操作電腦變得更 ...
  • awk [-field-separator] 'commands' input-file(s) ...
  • 在.Net框架中,如果您查看所有類型的的基類:System.Object類,將找到如下4個與相等判斷的方法: static Equals() virtual Equals() static ReferenceEquals() virtual GetHashCode() 除此之外,Microsoft已 ...
  • 配置的本質就是字元串的鍵值對,但是對於面向對象語言來說,能使用強類型的配置是何等的爽哉! 目錄 1. ASP.NET Core 配置系統 2. 強類型的 Options 3. Configure 方法 4. 源碼解析 ASP.NET Core 配置系統 在ASP.NET 4.X中,通常將配置存儲在 ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...