Beispiel #1
0
        public List<Student> GetAllStudents()
        {
            try
            {
                using (conn)
                {
                    empList = new List<Student>();

                    conn = new SqlConnection(connString);

                    command = new SqlCommand();
                    command.Connection = conn;
                    command.Connection.Open();
                    command.CommandType = CommandType.StoredProcedure;
                    command.CommandText = "up_getAllStudents";

                    SqlDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        Student objStudent = new Student();
                        objStudent.Nombre = reader.GetString(0);
                        objStudent.ApellidoPaterno = reader.GetString(1);
                        objStudent.ApellidoMaterno = reader.GetString(2);
                        objStudent.Edad = reader.GetInt32(3);
                        objStudent.Codigo = reader.GetInt32(4);
                        empList.Add(objStudent);
                    }
                    command.Connection.Close();
                    return empList;
                }

            }
            catch (Exception ex)
            {
                //err.ErrorMessage = ex.Message.ToString();
                throw;
            }
        }
 public Student UpdateStudent(string ID, Student updatePerson)
 {
     return objDal.UpdateStudent(ID,updatePerson);
 }
 public Student CreateStudent(Student createPerson)
 {
     return objDal.saveStudent(createPerson);
 }
Beispiel #4
0
        public Student UpdateStudent(String ID, Student emp)
        {
            try
            {
                using (conn)
                {
                    Student objStudent = new Student();
                    conn = new SqlConnection(connString);

                    command = new SqlCommand();
                    command.Connection = conn;
                    command.Connection.Open();
                    command.CommandType = CommandType.StoredProcedure;
                    command.CommandText = "up_updateStudent";

                    SqlParameter codigo = new SqlParameter("@Codigo", ID);
                    SqlParameter nombres = new SqlParameter("@Nombre", emp.Nombre);
                    SqlParameter apePat = new SqlParameter("@ApellidoPaterno", emp.ApellidoPaterno);
                    SqlParameter apeMat = new SqlParameter("@ApellidoMaterno", emp.ApellidoMaterno);
                    SqlParameter edad = new SqlParameter("@Edad", emp.Edad);

                    command.Parameters.AddRange(new SqlParameter[] { codigo, nombres, apePat, apeMat, edad });

                    SqlDataReader reader = command.ExecuteReader();

                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            objStudent.Nombre = reader.GetString(0);
                            objStudent.ApellidoPaterno = reader.GetString(1);
                            objStudent.ApellidoMaterno = reader.GetString(2);
                            objStudent.Edad = reader.GetInt32(3);
                            objStudent.Codigo = reader.GetInt32(4);
                        }
                    }
                    command.Connection.Close();

                    return objStudent;
                }
            }
            catch (Exception ex)
            {
                //err.ErrorMessage = ex.Message.ToString();
                throw;
            }
        }
Beispiel #5
0
        public Student GetStudentByID(String ID)
        {
            try
            {
                Student objStudent = new Student();

                conn = new SqlConnection(connString);

                command = new SqlCommand();
                command.Connection = conn;
                command.Connection.Open();
                command.CommandType = CommandType.StoredProcedure;
                command.CommandText = "up_getStudentByID";

                SqlParameter IDparam = new SqlParameter("@Codigo", ID);
                command.Parameters.Add(IDparam);
                SqlDataReader reader = command.ExecuteReader();

                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        objStudent.Nombre = reader.GetString(0);
                        objStudent.ApellidoPaterno = reader.GetString(1);
                        objStudent.ApellidoMaterno = reader.GetString(2);
                        objStudent.Edad = reader.GetInt32(3);
                        objStudent.Codigo = reader.GetInt32(4);
                    }
                }
                command.Connection.Close();

                return objStudent;
            }
            catch (Exception ex)
            {
                //err.ErrorMessage = ex.Message.ToString();
                throw;
            }
        }