public void GetAllStudentsBySchoolID(string _school_id, string studentfirstname) { JavaScriptSerializer serializer = new JavaScriptSerializer(); List <FoundStudents> liststudents = new List <FoundStudents>(); objSchool.myDatabase.CreateConnection(); objSchool.myDatabase.InitializeSQLCommandObject(objSchool.myDatabase.GetCurrentConnection, "select * from View_StudentGeneralInformation where school_id = '" + _school_id + "' and firstname like'" + studentfirstname + "%'"); try { objSchool.myDatabase.OpenConnection(); objSchool.myDatabase.obj_reader = objSchool.myDatabase.obj_sqlcommand.ExecuteReader(); if (objSchool.myDatabase.obj_reader.HasRows) { while (objSchool.myDatabase.obj_reader.Read()) { FoundStudents student = new FoundStudents(); student.FirstName = objSchool.myDatabase.obj_reader["firstname"].ToString(); student.LastName = objSchool.myDatabase.obj_reader["lastname"].ToString(); student.Gender = objSchool.myDatabase.obj_reader["Gender"].ToString(); student.photo = objSchool.myDatabase.obj_reader["photo"].ToString(); student.PrimaryEmail = objSchool.myDatabase.obj_reader["primary_email"].ToString(); student.Address = objSchool.myDatabase.obj_reader["address"].ToString(); student.SchoolID = objSchool.myDatabase.obj_reader["school_id"].ToString(); student.AuthorizedID = objSchool.myDatabase.obj_reader["authorized_id"].ToString(); student.GeneralID = objSchool.myDatabase.obj_reader["General_ID"].ToString(); student.Phone = objSchool.myDatabase.obj_reader["phone"].ToString(); student.StudentID = objSchool.myDatabase.obj_reader["Std_id"].ToString(); liststudents.Add(student); } } else { HttpContext.Current.Response.Write("No record found"); } } catch { } finally { objSchool.myDatabase.CloseConnection(); objSchool.myDatabase.obj_sqlcommand.Dispose(); } HttpContext.Current.Response.Write(serializer.Serialize(liststudents)); }
public void GetStudents(string _schoolID) { JavaScriptSerializer serializer = new JavaScriptSerializer(); List <FoundStudents> studentList = new List <FoundStudents>(); objSchool.myDatabase.CreateConnection(); objSchool.myDatabase.InitializeSQLCommandObject(objSchool.myDatabase.GetCurrentConnection, "select * from View_StudentGeneralInformation where school_id = '" + _schoolID + "'"); try { objSchool.myDatabase.OpenConnection(); objSchool.myDatabase.obj_reader = objSchool.myDatabase.obj_sqlcommand.ExecuteReader(); if (objSchool.myDatabase.obj_reader.HasRows) { while (objSchool.myDatabase.obj_reader.Read()) { FoundStudents objstuStudents = new FoundStudents(); objstuStudents.StudentID = objSchool.myDatabase.obj_reader["Std_id"].ToString(); objstuStudents.FirstName = objSchool.myDatabase.obj_reader["firstname"].ToString(); objstuStudents.LastName = objSchool.myDatabase.obj_reader["lastname"].ToString(); studentList.Add(objstuStudents); } } else { HttpContext.Current.Response.Write("No Record Found"); } } catch (Exception exception) { HttpContext.Current.Response.Write(exception.ToString()); } finally { objSchool.myDatabase.CloseConnection(); objSchool.myDatabase.obj_reader.Dispose(); } HttpContext.Current.Response.Write(serializer.Serialize(studentList)); }