コード例 #1
0
        /// <summary>
        /// 根据学生姓名查询学生信息
        /// </summary>
        public void Query_five()
        {
            Console.WriteLine("请输入要查询的学生姓名:");
            string Student_Name = Console.ReadLine();
            string sql          = string.Format("Select StudentNo,StudentName,Sex,GradeId,Phone,Address,BornDate,Email from Student Where StudentName Like '{0}%'", Student_Name);

            Console.WriteLine("================================================================================================================");
            Console.WriteLine("学号\t\t姓名\t性别\t年级\t联系电话\t地址\t\t出生日期\t\t邮箱");
            Console.WriteLine("================================================================================================================");
            try
            {
                var           reader = DBOperation.ExecuteReader(sql);
                StringBuilder buil   = new StringBuilder();
                while (reader.Read())
                {
                    buil.AppendFormat("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}", reader["StudentNo"], reader["StudentName"], reader["Sex"], reader["GradeId"], reader["Phone"], reader["Address"], reader["BornDate"], reader["Email"]);
                    Console.WriteLine(buil);
                    buil.Length = 0;
                }
                reader.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine("出现异常:{0}", ex.Message);
            }
            finally
            {
                DBOperation.CloseConnection();
                //Console.WriteLine("数据库关闭成功!");
            }
        }
コード例 #2
0
        /// <summary>
        /// 按学号查询学生姓名
        /// </summary>
        public void Query_four()
        {
            Console.WriteLine("请输入要查询的学生学号:");
            string Student_id = Console.ReadLine();
            string sql        = string.Format("Select StudentName from Student Where StudentNo Like '%{0}'", Student_id);

            try
            {
                var           reader = DBOperation.ExecuteReader(sql);
                StringBuilder buil   = new StringBuilder();
                while (reader.Read())
                {
                    buil.AppendFormat("学号是:{0}的学生姓名为:{1}", Student_id, reader["StudentName"]);
                    Console.WriteLine(buil);
                    buil.Length = 0;
                }
                reader.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine("出现异常:{0}", ex.Message);
            }
            finally
            {
                DBOperation.CloseConnection();
                //Console.WriteLine("数据库关闭成功!");
            }
        }
コード例 #3
0
        /// <summary>
        /// 查询学生信息
        /// </summary>
        public void Query_three()
        {
            string sql = "Select StudentNo,StudentName from Student";

            Console.WriteLine("====================================================");
            Console.WriteLine("学号\t\t\t姓名");
            Console.WriteLine("====================================================");
            try
            {
                var           reader = DBOperation.ExecuteReader(sql);
                StringBuilder buil   = new StringBuilder();
                while (reader.Read())
                {
                    buil.AppendFormat("{0}\t\t{1}", reader["StudentNo"], reader["StudentName"]);
                    Console.WriteLine(buil);
                    buil.Length = 0;
                }
                reader.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine("出现异常:{0}", ex.Message);
            }
            finally
            {
                DBOperation.CloseConnection();
                //Console.WriteLine("数据库关闭成功!");
            }
        }
コード例 #4
0
 int count;    //输入次数
 /// <summary>
 /// 判断用户密码是否有误
 /// </summary>
 public void Query_one()
 {
     do
     {
         //登陆账号
         Console.WriteLine("请输入用户名:");
         name = Console.ReadLine();
         Console.WriteLine("请输入密码:");
         string pwo = Console.ReadLine();
         string sql = string.Format("Select StudentName,LoginPwe from Student Where StudentName='{0}' and LoginPwe='{1}'", name, pwo);
         try
         {
             var reader = DBOperation.ExecuteReader(sql);
             if (reader.HasRows != true)
             {
                 Console.WriteLine("\n登陆失败!用户名或密码有误!");
                 count++;
             }
             else
             {
                 Console.WriteLine("登陆成功!欢迎:{0}\n\n欢迎使用学生管理系统", name);
                 reader.Close();
                 Choose_one();
             }
         }
         catch (Exception ex)
         {
             Console.WriteLine("出现异常:{0}", ex.Message);
         }
         finally
         {
             DBOperation.CloseConnection();
             //Console.WriteLine("数据库关闭成功!");
         }
     } while (count < 3);
     Console.WriteLine("\n您输入三次有误,本次退出!");
 }