public StudentWithDepartmentVM GetStudent(string regNo) { SqlConnection connection = new SqlConnection(connectionString); string query = "SELECT * FROM StudentWithDepartment WHERE RegNo='" + regNo + "'"; SqlCommand command = new SqlCommand(query, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); StudentWithDepartmentVM student = null; if (reader.HasRows) { reader.Read(); student = new StudentWithDepartmentVM(); student.StudentId = Convert.ToInt32(reader["StudentId"]); student.RegNo = reader["RegNo"].ToString(); student.StudentName = reader["StudentName"].ToString(); student.ContactNo = reader["ContactNo"].ToString(); student.Email = reader["Email"].ToString(); student.DeptId = Convert.ToInt32(reader["DeptId"]); student.DeptCode = reader["DeptCode"].ToString(); student.DeptName = reader["DeptName"].ToString(); } reader.Close(); connection.Close(); return(student); }
protected void Page_Load(object sender, EventArgs e) { int id = Convert.ToInt32(Request.QueryString["id"]); if (id == 0) { Response.Redirect("~/UI/IndexUI.aspx"); } else { StudentWithDepartmentVM student = studentManager.GetStudentById(id); if (student == null) { Response.Redirect("~/UI/IndexUI.aspx"); } else { nameLabel.Text = student.StudentName; regNoLabel.Text = student.RegNo; contactLabel.Text = student.ContactNo; emailLabel.Text = student.Email; departmentLabel.Text = student.DeptCode; ViewState["Id"] = student.StudentId; } } }
public List <StudentWithDepartmentVM> PopulateStudentList() { SqlConnection connection = new SqlConnection(connectionString); string query = "SELECT * FROM StudentWithDepartment"; SqlCommand command = new SqlCommand(query, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); List <StudentWithDepartmentVM> students = new List <StudentWithDepartmentVM>(); while (reader.Read()) { StudentWithDepartmentVM student = new StudentWithDepartmentVM(); student.StudentId = Convert.ToInt32(reader["StudentId"]); student.RegNo = reader["RegNo"].ToString(); student.StudentName = reader["StudentName"].ToString(); student.ContactNo = reader["ContactNo"].ToString(); student.Email = reader["Email"].ToString(); student.DeptId = Convert.ToInt32(reader["DeptId"]); student.DeptCode = reader["DeptCode"].ToString(); student.DeptName = reader["DeptName"].ToString(); students.Add(student); } reader.Close(); connection.Close(); return(students); }
public StudentWithDepartmentVM GetStudent(string regNo) { StudentWithDepartmentVM student = gateway.GetStudent(regNo); return(student); }