Ejemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            string          n    = Form1.name;
            OleDbConnection conn = new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=C:\\Users\\zhongbo\\Documents\\Visual Studio 2013\\Projects\\学生选课登陆系统\\学生选课登陆系统\\Resources\\学生选课.mdb"); //创建连接

            conn.Open();                                                                                                                                                                                          //打开连接
            OleDbCommand comm = new OleDbCommand();                                                                                                                                                               //创建OleDbCommand对象

            comm.Connection  = conn;                                                                                                                                                                              //以上代码连接并打开数据库
            comm.CommandText = "select * from 登录 where 用户名='" + n + "'";                                                                                                                                          //根据登录界面输入的信息去查询数据库内容
            OleDbDataReader dr;

            dr = comm.ExecuteReader();//执行连接
            if (dr.Read() == true)
            {
                if (dr["角色"].ToString() == "学生")//若为学生用户则返回学生用户主界面         
                {
                    this.Hide();
                    StudentForm aa = new StudentForm();
                    aa.Show();
                }
                else if (dr["角色"].ToString() == "教师")//若为教师用户则返回学生用户主界面             
                {
                    this.Hide();
                    TeacherForm aa = new TeacherForm();
                    aa.Show();
                }
            }
            else
            {
                MessageBox.Show("出错了哦!");
            }
            conn.Close();
        }
Ejemplo n.º 2
0
        private void button2_Click(object sender, EventArgs e)
        {
            /*  SqlConnection conn = new SqlConnection();
             * conn.ConnectionString = "server=.;database=db_Person;uid=sa;pwd=123456";
             * conn.Open();          //打开连接  
             * SqlCommand comm = new SqlCommand();      
             * comm.Connection = conn;//以上代码连接并打开数据库 
             * comm.CommandType = CommandType.Text;
             * comm.CommandText = "select * from login where username='******'";//根据登录界面输入的信息去查询数据库内容  
             * SqlDataReader dr;
             * dr = comm.ExecuteReader();*/
            OleDbConnection conn = new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=C:\\Users\\zhongbo\\Documents\\Visual Studio 2013\\Projects\\学生选课登陆系统\\学生选课登陆系统\\Resources\\学生选课.mdb"); //创建连接

            conn.Open();                                                                                                                                                                                          //打开连接
            OleDbCommand comm = new OleDbCommand();                                                                                                                                                               //创建OleDbCommand对象

            comm.Connection  = conn;                                                                                                                                                                              //以上代码连接并打开数据库
            comm.CommandText = "select * from 登录 where 用户名='" + textBox1.Text + "'";                                                                                                                              //根据登录界面输入的信息去查询数据库内容
            OleDbDataReader dr;

            dr = comm.ExecuteReader();//执行连接
            if (dr.Read() == true)
            {
                if (dr["密码"].ToString() == textBox2.Text && dr["角色"].ToString() == comboBox1.Text)
                {
                    name = textBox1.Text;
                    if (dr["角色"].ToString() == "学生")
                    {
                        this.Hide();
                        StudentForm stu = new StudentForm();
                        stu.Show();
                    }
                    else if (dr["角色"].ToString() == "教师")
                    {
                        this.Hide();
                        TeacherForm tea = new TeacherForm();
                        tea.Show();
                    }
                }
                else
                {
                    MessageBox.Show("登陆角色错误或密码错误!");
                }
            }
            else
            {
                MessageBox.Show("无此用户!");
            }
            conn.Close();
        }
Ejemplo n.º 3
0
        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            string          n    = Form1.name;
            OleDbConnection conn = new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=C:\\Users\\zhongbo\\Documents\\Visual Studio 2013\\Projects\\学生选课登陆系统\\学生选课登陆系统\\Resources\\学生选课.mdb"); //创建连接

            conn.Open();                                                                                                                                                                                          //打开连接
            OleDbCommand comm = new OleDbCommand();                                                                                                                                                               //创建OleDbCommand对象

            comm.Connection = conn;                                                                                                                                                                               //以上代码连接并打开数据库
            // comm.CommandText = "INSERT INTO xuanke(用户名,CID) VALUES('"+n+"','"+dataGridView1[0,dataGridView1.CurrentCell.RowIndex].Value+"')";
            string strSQL = "INSERT INTO xuanke(用户名,CID) " +
                            "VALUES ( '" + n + "','" + dataGridView1[0, dataGridView1.CurrentCell.RowIndex].Value + "')";

            comm = new OleDbCommand(strSQL, conn);
            comm.ExecuteNonQuery();
            this.Hide();

            comm.CommandText = "select * from 登录 where 用户名='" + n + "'";//根据登录界面输入的信息去查询数据库内容
            OleDbDataReader dr;

            dr = comm.ExecuteReader();//执行连接
            if (dr.Read() == true)
            {
                if (dr["角色"].ToString() == "学生")//若为学生用户则返回学生用户主界面         
                {
                    this.Hide();
                    StudentForm aa = new StudentForm();
                    aa.Show();
                }
                else if (dr["角色"].ToString() == "教师")//若为教师用户则返回学生用户主界面             
                {
                    this.Hide();
                    TeacherForm aa = new TeacherForm();
                    aa.Show();
                }
            }
            else
            {
                MessageBox.Show("出错了哦!");
            }  
                        conn.Close();  
        }