标题:添加学生信息后添加该学生登陆信息出错,这是为什么?
取消只看楼主
清波无雯
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2014-9-5
结帖率:100%
已结贴  问题点数:20 回复次数:0 
添加学生信息后添加该学生登陆信息出错,这是为什么?
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();  //关闭数据库连接

            }
搜索更多相关主题的帖子: insert values 信息 
2014-09-09 10:26



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-435865-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.281778 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved