C#用户登录界面程序.doc_第1页
C#用户登录界面程序.doc_第2页
C#用户登录界面程序.doc_第3页
C#用户登录界面程序.doc_第4页
C#用户登录界面程序.doc_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

一、数据库连接方式:由于使用Acess2000连接数据库,所以要加上using System.Data.OleDb;空间,可以使用如下方式连接到数据库 string str = string str = Provider=Microsoft.Jet.OLEDB.4.0;Data Source=xsxx.mdb;程序总体如下:OleDbDataAdapter adapter; DataTable table = new DataTable(); string str = Provider=Microsoft.Jet.OLEDB.4.0;Data Source=liqi.mdb; OleDbConnection con = new OleDbConnection();二、界面设计:1、登入界面界面框图如下:图3-1 登入界面2、注册界面框图如下:图3-2 注册界面3、学生信息管理系统界面框图如下:图3-3 学生信息管理系统界面三、主要功能代码1登入界面代码:public partial class Form1 : Form OleDbDataAdapter adapter; /数据库连接 DataTable table = new DataTable(); string str = Provider=Microsoft.Jet.OLEDB.4.0;Data Source=liqi.mdb; OleDbConnection con = new OleDbConnection(); public Form1() InitializeComponent(); private void button1_Click(object sender, EventArgs e) if (textBox1.Text != & textBox2.Text != ) string sql = select * from 信息 where 学号= + textBox1.Text + and 密码= + textBox2.Text + ; adapter = new OleDbDataAdapter(sql, str); OleDbCommandBuilder buider = new OleDbCommandBuilder(adapter); adapter.InsertCommand = buider.GetInsertCommand(); table.Clear(); adapter.Fill(table); if (table.Rows.Count 0) Form f3 = new Form3(); f3.Show(); this.Hide(); else MessageBox.Show(用户名或密码不能空); /登入 private void button3_Click(object sender, EventArgs e) Form f2 = new Form2();/打开注册界面 f2.Show(); this.Hide(); private void button2_Click(object sender, EventArgs e) Application.Exit(); 功能分析:当在登入界面时,可以使用数据库中有的数据登入学生信息管理系统,也可以进入注册界面成为新的用户。2、注册界面代码:public partial class Form2 : Form OleDbDataAdapter adapter; /数据库连接 DataTable table = new DataTable(); string str = Provider=Microsoft.Jet.OLEDB.4.0;Data Source=liqi.mdb; OleDbConnection con = new OleDbConnection(); public Form2() InitializeComponent(); con.ConnectionString = str; private void button2_Click(object sender, EventArgs e) textBox1.Text = ; textBox2.Text = ; textBox4.Text = ; textBox5.Text = ; textBox3.Text = ; /取消注册 private void button1_Click(object sender, EventArgs e) if (textBox2.Text = & textBox3.Text = ) label4.Text = 请输入密码; else if (textBox2.Text = textBox3.Text) string b = textBox2.Text; string c = textBox1.Text; string a = textBox4.Text; string d = textBox5.Text; OleDbCommand cmd = new OleDbCommand(insert into 信息(学号,姓名,专业,密码) values( + c + , + a + , + d + , + b + ), con); con.Open(); cmd.Connection = con; cmd.ExecuteNonQuery(); con.Close(); Form1 f3 = new Form1(); f3.Show(); this.Hide(); /注册新用户 功能分析:当不能登入学生管理系统时,可以使用注册界面注册成为用户,而注册的信息将会进入数据库中。注册成功后将会回到登入界面,可以使用新用户登入。3、学生管理系统界面代码:public partial class Form3 : Form OleDbDataAdapter adapter; /数据库连接 DataTable table = new DataTable(); string str = Provider=Microsoft.Jet.OLEDB.4.0;Data Source=liqi.mdb; OleDbConnection con = new OleDbConnection(); public Form3() InitializeComponent(); private void Form3_Load(object sender, EventArgs e) string sql = select * from 信息; adapter = new OleDbDataAdapter(sql, str); private void 浏览ToolStripMenuItem_Click(object sender, EventArgs e) con.ConnectionString = str; string sql = select * from 信息; adapter = new OleDbDataAdapter(sql, str); OleDbCommandBuilder buider = new OleDbCommandBuilder(adapter); table.Clear(); adapter.Fill(table); dataGridView1.DataSource = table; /浏览功能,可以看到数据信息 private void 精确查询ToolStripMenuItem_Click(object sender, EventArgs e) adapter.SelectCommand.CommandText = Select * from 信息 where 学号 = + textBox1.Text + ; table.Clear(); adapter.Fill(table); dataGridView1.DataSource = table; /精确查询功能,可输入完整学号查询信息 private void 模糊查询ToolStripMenuItem_Click(object sender, EventArgs e) adapter.SelectCommand.CommandText = Select * from 信息 where 学号 like + textBox1.Text + %; table.Clear(); adapter.Fill(table); dataGridView1.DataSource = table; /模糊查询功能,输入学号前几个数字就可查询 private void 添加ToolStripMenuItem_Click(object sender, EventArgs e) OleDbConnection con = new OleDbConnection(); con.ConnectionString = str; string sex; if (radioButton1.Checked = true) sex = 男; else sex = 女; OleDbCommand cmd = new OleDbCommand(insert into 信息(学号,姓名,性别,生日,籍贯,专业,密码) values( + textBox1.Text + , + textBox2.Text + , + sex + , + textBox3.Text + , + textBox4.Text + , + textBox5.Text + , + textBox6.Text + ), con); con.Open(); cmd.Connection = con; cmd.ExecuteNonQuery(); con.Close(); adapter.SelectCommand.CommandText = select * from 信息 ; table.Clear(); adapter.Fill(table); adapter.Update(table); /可添加数据信息 private void 修改ToolStripMenuItem_Click(object sender, EventArgs e) OleDbConnection con = new OleDbConnection(); con.ConnectionString = str; string sex; if (radioButton1.Checked = true) sex = 男; else sex = 女; OleDbCommand cmd = new OleDbCommand(update 信息 set 姓名= + textBox2.Text + ,性别= + sex + ,生日= + textBox3.Text + ,籍贯= + textBox4.Text + ,专业= + textBox5.Text + ,密码= + textBox6.Text + where 学号= + textBox1.Text + , con); con.Open(); cmd.Connection = con; cmd.ExecuteNonQuery(); con.Close(); adapter.SelectCommand.CommandText = select * from 信息 ; table.Clear(); adapter.Fill(table); adapter.Update(table); /可修改数据信息 private void 删除ToolStripMenuItem_Click(object sender, EventArgs e) OleDbConnection con = new OleDbConnection(); con.ConnectionString = str; OleDbCommand cmd = new OleDbCommand(delete from 信息 where 学号= + textBox1.Text + , con); con.Open(); cmd.Connection = con; cmd.ExecuteNonQuery(); con.Close(); adapter.SelectCommand.CommandText = select * from 信息 ; table.Clear(); adapter.Fill(table); adapter.Update(table); /可删除数据信息 private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e) adapter.SelectCommand.CommandText = select * from 信息 ; table.Clear(); adapter.Fill(table); adapter.Update(table); private void 退出ToolStripMenuItem_Click(obj

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论