Example #1
0
        /// <summary>
        /// 根据班级Id查询学生列表
        /// </summary>
        /// <param name="classId"></param>
        /// <returns>返回学生列表</returns>
        public List <StudentExt> GetStudentByClassId(int classId)
        {
            string sql = "select StudentId,StudentName, Gender, Birthday, StudentIdNo, PhoneNumber, ClassName";

            sql += " from Students inner join StudentClass on Students.ClassId=StudentClass.ClassId";
            sql += " where StudentClass.ClassId=" + classId;
            List <StudentExt> studentList = new List <StudentExt>();
            SqlDataReader     reader      = SQLHelper.GetReader(sql);

            //try
            //{
            //    while (reader.Read())
            //    {
            //        studentList.Add(new StudentExt
            //        {
            //            StudentId = Convert.ToInt32(reader["StudentId"]),
            //            StudentName = reader["StudentName"].ToString(),
            //            Gender = reader["Gender"].ToString(),
            //            Birthday = Convert.ToDateTime(reader["Birthday"]),
            //            StudentIdNo = reader["StudentIdNo"].ToString(),
            //            PhoneNumber = reader["PhoneNumber"].ToString(),
            //            ClassName = reader["ClassName"].ToString(),
            //        }); ;
            //    }
            //    reader.Close();
            //    return studentList;
            //}
            //catch (Exception ex)
            //{
            //    throw new Exception("查询学生列表时数据库访问异常" + ex.Message);
            //}
            return(db.GetAllModeList <StudentExt>(reader));
        }