用C#连接到数据库实现学生学籍管理系统(二)https://developer.aliyun.com/article/1382522
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data .OleDb ; namespace 学生学籍管理系统 { public partial class Scoreupdate : Form { CurrencyManager cm; public Scoreupdate() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { } private void button2_Click(object sender, EventArgs e) { } private void Scoreupdate_Load(object sender, EventArgs e) { string connstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=xsxjdb.mdb"; string sqlstring = "select * from ScoreInfo "; OleDbConnection oldconn = new OleDbConnection(connstring); oldconn.Open(); OleDbDataAdapter oda = new OleDbDataAdapter(sqlstring, connstring); DataSet ds = new DataSet(); oda.Fill(ds, "ScoreInfo"); textBox1.DataBindings.Add("Text", ds, "ScoreInfo.Num"); textBox2.DataBindings.Add("Text", ds, "ScoreInfo.Name"); textBox3.DataBindings.Add("Text", ds, "ScoreInfo.ClassName"); textBox4.DataBindings.Add("Text", ds, "ScoreInfo.CourseName"); textBox5.DataBindings.Add("Text", ds, "ScoreInfo.Fraction"); textBox6.DataBindings.Add("Text", ds, "ScoreInfo.CourseType"); textBox7.DataBindings.Add("Text", ds, "ScoreInfo.State"); cm = (CurrencyManager)this.BindingContext[ds, "ScoreInfo"]; cm.Position = 0; } private void button2_Click_1(object sender, EventArgs e) { cm.Position = 0; } private void button5_Click(object sender, EventArgs e) { this.cm.Position = this.cm.Count - 1; } private void button3_Click(object sender, EventArgs e) { if (this.cm.Position == 0) { MessageBox.Show("已经是第一条记录", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } else this.cm.Position--; } private void button4_Click(object sender, EventArgs e) { if (this.cm.Position == this.cm.Count - 1) { MessageBox.Show("已经是末一条记录", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } else this.cm.Position++; } private void button6_Click(object sender, EventArgs e) { string upstring = "update ScoreInfo set Name='"+ textBox2.Text.Trim() + "',ClassName='" + textBox3.Text.Trim() + "',CourseName='"+ textBox4.Text.Trim() + "',Fraction='"+ textBox5.Text.Trim() + "',CourseType='"+ textBox7.Text.Trim() + "',State='"+ textBox6.Text.Trim() + "' where Num='" + textBox1.Text.Trim() + "'"; string connstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=xsxjdb.mdb"; OleDbConnection oldconn = new OleDbConnection(connstring); oldconn.Open(); OleDbCommand oldcomm = new OleDbCommand(upstring, oldconn); oldcomm.ExecuteNonQuery(); MessageBox.Show("更新成功!"); } private void button7_Click(object sender, EventArgs e) { this.Close(); } } }
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.OleDb; namespace 学生学籍管理系统 { public partial class ScoreView : Form { public ScoreView() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { } private void button2_Click(object sender, EventArgs e) { string connstring = "provider=microsoft.Jet.OLEDB.4.0;DaTa Source=xsxjdb.mdb"; string Sqlstring = "select Num as 学号,Name as 姓名,ClassName as 教师名,CourseName as 课程名,Fraction as 分数,CourseType as 课程类型,State as 状态 from ScoreInfo where Fraction>=400"; OleDbConnection oldconn = new OleDbConnection(connstring); oldconn.Open(); OleDbDataAdapter oda = new OleDbDataAdapter(Sqlstring, connstring); DataSet ds = new DataSet(); oda.Fill(ds, "ScoreInfo"); dataGridView1.DataSource = ds.Tables["ScoreInfo"]; string sql = "select count(*) from ScoreInfo where Fraction>=400"; label1.Text ="及格人数有"+sql.ToString () ; } private void button3_Click(object sender, EventArgs e) { string connstring = "provider=microsoft.Jet.OLEDB.4.0;DaTa Source=xsxjdb.mdb"; string Sqlstring = "select Num as 学号,Name as 姓名,ClassName as 教师名,CourseName as 课程名,Fraction as 分数,CourseType as 课程类型,State as 状态 from ScoreInfo where Fraction<=400"; OleDbConnection oldconn = new OleDbConnection(connstring); oldconn.Open(); OleDbDataAdapter oda = new OleDbDataAdapter(Sqlstring, connstring); DataSet ds = new DataSet(); oda.Fill(ds, "ScoreInfo"); dataGridView1.DataSource = ds.Tables["ScoreInfo"]; string sql = "select count(*) from ScoreInfo where Fraction<=400"; label1.Text = "不及格人数有" + sql.ToString(); } private void ScoreView_Load(object sender, EventArgs e) { string connstring = "provider=microsoft.Jet.OLEDB.4.0;DaTa Source=xsxjdb.mdb"; string Sqlstring = "select Num as 学号,Name as 姓名,ClassName as 教师名,CourseName as 课程名,Fraction as 分数,CourseType as 课程类型,State as 状态 from ScoreInfo"; OleDbConnection oldconn = new OleDbConnection(connstring); oldconn.Open(); OleDbDataAdapter oda = new OleDbDataAdapter(Sqlstring, connstring); DataSet ds = new DataSet(); oda.Fill(ds, "ScoreInfo"); dataGridView1.DataSource = ds.Tables["ScoreInfo"]; label1.Text = ""; } private void button1_Click_1(object sender, EventArgs e) { string connstring = "provider=microsoft.Jet.OLEDB.4.0;DaTa Source=xsxjdb.mdb"; string Sqlstring = "select Num as 学号,Name as 姓名,ClassName as 教师名,CourseName as 课程名,Fraction as 分数,CourseType as 课程类型,State as 状态 from ScoreInfo where CourseType='" + comboBox1.Text.Trim() + "'"; OleDbConnection oldconn = new OleDbConnection(connstring); oldconn.Open(); OleDbDataAdapter oda = new OleDbDataAdapter(Sqlstring, connstring); DataSet ds = new DataSet(); oda.Fill(ds, "ScoreInfo"); dataGridView1.DataSource = ds.Tables["ScoreInfo"]; } private void button4_Click(object sender, EventArgs e) { this.Close(); } } }
四、总结
博主在设计这个学生学籍管理系统的时候也遇到了一些困难,不过都慢慢解决了,至于体会与心得,由于时间仓促,这里就不一一和大家分享了。大家可以关注我的博客,我会不定期的给大家分享文章,欢迎大家关注和留言哦!