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圖