/// <summary> /// 统计学生人数 /// </summary> public void Query_two() { string sql = "Select COUNT(StudentName) from Student"; try { var iRed = DBOperation.ExecuteScalar(sql); if (iRed > 0) { Console.WriteLine("学生人数为:{0}名", iRed); } else { Console.WriteLine("获取失败!"); } } catch (Exception ex) { Console.WriteLine("出现异常:{0}", ex.Message); } }
/// <summary> /// 新增年级 /// </summary> public void New_one() { Console.WriteLine("请输入待插入的年级名称:"); string Grade_Name = Console.ReadLine(); string sql = string.Format("Insert Grade Values('{0}')", Grade_Name); try { var New = DBOperation.ExecuteNonQuery(sql); if (New > 0) { Console.WriteLine("插入成功!"); } else { Console.WriteLine("插入失败!"); } } catch (Exception ex) { Console.WriteLine("出现异常:{0}", ex.Message); } }
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您输入三次有误,本次退出!"); }