public List <DepartmentWiseStudentView> GetAllStudents() { List <DepartmentWiseStudentView> studentList = new List <DepartmentWiseStudentView>(); SqlConnection connection = new SqlConnection(connectionString); string query = "SELECT * FROM DepartmentWiseStudent"; SqlCommand command = new SqlCommand(query, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { DepartmentWiseStudentView view = new DepartmentWiseStudentView(); view.Name = reader["StudentName"].ToString(); view.RegNo = reader["RegNo"].ToString(); view.Mobile = reader["MobileNo"].ToString(); view.Email = reader["Email"].ToString(); view.Age = (int)reader["Age"]; view.Address = reader["Address"].ToString(); view.DeptName = reader["DeptName"].ToString(); view.DeptCode = reader["DeptCode"].ToString(); studentList.Add(view); } reader.Close(); connection.Close(); return(studentList); }
public List <DepartmentWiseStudentView> showAllStudent() { List <DepartmentWiseStudentView> studentList = new List <DepartmentWiseStudentView>(); string connectionString = @"Server=DESKTOP-KIQISOE\MUSHFIQSQL;Database=InformationManagementDB; Integrated Security=true;"; SqlConnection sqlConnection = new SqlConnection(connectionString); string query = "SELECT * FROM DepartmentWiseStudent"; SqlCommand command = new SqlCommand(query, sqlConnection); sqlConnection.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { DepartmentWiseStudentView departmentWiseStudent = new DepartmentWiseStudentView(); departmentWiseStudent.StudentName = reader["Student_Name"].ToString(); departmentWiseStudent.RegNo = reader["Student_Reg_No"].ToString(); departmentWiseStudent.MobileNo = reader["Student_Mobile_no"].ToString(); departmentWiseStudent.Email = reader["Student_Email"].ToString(); departmentWiseStudent.Address = reader["Student_Address"].ToString(); departmentWiseStudent.Department = reader["DepartmentName"].ToString(); departmentWiseStudent.Code = reader["DepartmentCode"].ToString(); studentList.Add(departmentWiseStudent); } sqlConnection.Close(); return(studentList); }