c#学生信息管理系统
1! 注册的信息无法进入数据库!!!2! 管理员对数据库内的学生信息的修改和查询代码!!!
/*------------------注册代码-----------------------*/
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsFormsApplication1
{
public partial class Formregister : Form
{
public Formregister()
{
InitializeComponent();
}
private void Formregister_Load(object sender, EventArgs e)
{
}
public bool bbool;
private void buttonconform_Click(object sender, EventArgs e)
{
Formlog f2 = new Formlog();
string User, Pwd;
string StrConnection = @"Data Source=JIAOWOERYE-PC;Initial Catalog=mydatabase;Integrated Security=True";
SqlConnection con = new SqlConnection(StrConnection);
con.Open();
string str= "select * from TableStudent";
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
= str;
= CommandType.Text;
cmd.ExecuteNonQuery();
SqlDataReader reader = cmd.ExecuteReader();
while(reader.Read())
{
User = reader["studentName"].ToString();
Pwd = reader["mima"].ToString();
if (textBoxname.Text.Trim () == reader["studentName"].ToString().Trim())
{
MessageBox.Show("用户存在");
bbool =true;
return; }
else
if (textBoxname.Text.Trim() != reader["studentName"].ToString().Trim())
{
MessageBox.Show("恭喜,该用户名可以使用");
bbool = false;
}
}
if (bbool == false)
{
= "insert into TableStudent values('" + textBoxnum.Text + "','" + textBoxname.Text + "','" + textBoxclass.Text + "','" + textBoxmima.Text + "','" + textBoxrealname.Text + "')";
con.Close();
MessageBox.Show("注册成功!");
f2.Show();//运行登陆程序
this.Hide();
}
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Formlog f2 = new Formlog();
f2.Show();
}
}
}
/*---------------------------------------管理员管理代码------------------------*/
//有错误,要求读取后可以选中一项修改,求大神更改
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsFormsApplication1
{
public partial class Formcontrol : Form
{
public Formcontrol()
{
InitializeComponent();
}
private void comboBoxnumber_SelectedIndexChanged(object sender, EventArgs e)
{
string StrConnection = @"Data Source=JIAOWOERYE-PC;Initial Catalog=mydatabase;Integrated Security=True";
SqlConnection con = new SqlConnection(StrConnection);
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
= CommandType.Text;
= "select studentNumber from TableStudent where studentNumber =" + comboBoxnumber.Text;
SqlDataReader reader = cmd.ExecuteReader();
reader.Read();
textBoxnum.Text = reader.GetValue(reader.GetOrdinal("studentNumber")).ToString().Trim();
textBoxrealname.Text = reader.GetValue(reader.GetOrdinal("studentName")).ToString().Trim();
textBoxmima.Text = reader.GetValue(reader.GetOrdinal("male")).ToString().Trim();
textBoxname.Text = reader.GetValue(reader.GetOrdinal("age")).ToString().Trim();
//textBoxdepart.Text = reader.GetValue(reader.GetOrdinal("deparement")).ToString().Trim();
textBoxclass.Text = reader.GetValue(reader.GetOrdinal("class")).ToString().Trim();
}
private void buttonchange_Click(object sender, EventArgs e)
{
}
}
}
//}