示例#1
0
        public List <ParentEnrollment> GetTheAssociatedEnrollmentsForTheParent(int id)
        {
            List <ParentEnrollment> Enrollments = new List <ParentEnrollment>();


            // var connectionString = @"Data Source=(LocalDB)\v11.0;;AttachDbFileName=|DataDirectory|\SchoolDB.mdf; Integrated Security=SSPI; Connection Timeout=1200";


            using (SqlConnection myConnection = new SqlConnection(connectionString))
            {
                string     oString = ("Select * FROM [ParentEnrollment] Where [ParentEnrollment].fk_ParentId = " + id + ";");
                SqlCommand oCmd    = new SqlCommand(oString, myConnection);
                myConnection.Open();
                using (SqlDataReader oReader = oCmd.ExecuteReader())
                {
                    while (oReader.Read())
                    {
                        ParentEnrollment parentEnrollment = new ParentEnrollment();
                        parentEnrollment.Fkparentid     = Convert.ToInt32(oReader["fk_ParentId"]);
                        parentEnrollment.FkEnrollmentid = Convert.ToInt32(oReader["fk_EnrollmentId"]);
                        Enrollments.Add(parentEnrollment);
                    }

                    myConnection.Close();
                }
                return(Enrollments);
            }
        }
示例#2
0
        /*  public bool InsertStudentFromEnrollment(Student student, Enrollment enrollment)
         * {
         *
         *
         *
         *
         *    bool success = true;
         *    int result = 0;
         *    try
         *    {
         *        DB.Open();
         *
         *        result = DB.Exec("BEGIN TRANSACTION BEGIN TRY INSERT INTO [StudentParent](fk_StudentId, fk_ParentId)" +
         *         "VALUES(" + studentParent.Fkstudentid + "," + studentParent.Fkparentid + "); COMMIT TRANSACTION END TRY  BEGIN CATCH  ROLLBACK TRANSACTION  END CATCH");
         *
         *        if (result == -1)
         *        {
         *            throw new Exception();
         *        }
         *    }
         *    catch (SqlException sqlException)
         *    {
         *        Debug.Write(sqlException.ToString());
         *        success = false;
         *    }
         *
         *    finally
         *    {
         *        DB.Close();
         *    }
         *    return success;
         * }*/


        public List <ParentEnrollment> GetParentEnrollment(int id)
        {
            List <ParentEnrollment> studentParentsList = new List <ParentEnrollment>();


            // var con = connectionString;


            using (SqlConnection myConnection = new SqlConnection(connectionString))
            {
                string     oString = "SELECT * FROM ParentEnrollment WHERE [fk_EnrollmentId]=" + id + "OR [fk_ParentId]=" + id;
                SqlCommand oCmd    = new SqlCommand(oString, myConnection);
                myConnection.Open();
                using (SqlDataReader oReader = oCmd.ExecuteReader())
                {
                    while (oReader.Read())
                    {
                        ParentEnrollment parentenrollment = new ParentEnrollment();
                        parentenrollment.Fkparentid     = Convert.ToInt32(oReader["fk_ParentId"]);
                        parentenrollment.FkEnrollmentid = Convert.ToInt32(oReader["fk_EnrollmentId"]);
                        studentParentsList.Add(parentenrollment);
                    }

                    myConnection.Close();
                }
                return(studentParentsList);
            }
        }