添加学生信息后添加该学生登陆信息出错,这是为什么?
try{
string sqll = "insert into Student(Sno,Sname,Ssex,Sdept,Sage) values ('"+stu_sno.Text.Trim ()+"','"+stu_sname.Text .Trim ()
+"','"+stu_sex.Text .Trim ()+"','"+stu_dept.Text.Trim()+"',"+int.Parse (stu_age.Text.Trim())+")";
//插入前检查该学生信息是否已经存在
//存在该学生,信息无法插入
conn = new OleDbConnection(myconn);
conn.Open();
cmd = new OleDbCommand("select * from Student where Sno = '"+stu_sno.Text.Trim ()+"'",conn);
read = cmd.ExecuteReader();
if (read.Read()) //存在该学生
{
MessageBox.Show("该学生信息存在,添加无效!");
}
else //添加学生信息
{
cmd = new OleDbCommand(sqll, conn);
cmd.ExecuteNonQuery();//学生信息添加
//添加该生注册信息,在Student_Login表中插入数据,学号,和密码(默认为111)
string pwd = "111";
string ssql = "insert into Student_Login(Sno,Password) values ('" + stu_sno.Text.Trim() + "','" + pwd + "')";
OleDbCommand cc = new OleDbCommand(ssql,conn);
cc.ExecuteNonQuery();
}
}
catch (Exception ee)
{
MessageBox.Show(ee.ToString());
}
finally
{
read.Close();
conn.Close(); //关闭数据库连接
}