Пример #1
0
        public static void Delete(Student Student)
        {
            _command = new SqlCommand("delete from StudentList where SerialNo=@SerialNo");

            _command.Parameters.AddWithValue("@SerialNo", Student.SerialNo);

            try
            {
                _connection.Open();
                _transaction = _connection.BeginTransaction();

                _command.Connection  = _connection;
                _command.Transaction = _transaction;

                DalCourse.Delete(true, Student.StudentID, _connection, _transaction);

                _command.ExecuteNonQuery();

                _transaction.Commit();
                _connection.Close();
            }
            catch (Exception ex)
            {
                _transaction.Rollback();
                _connection.Close();
                throw ex;
            }
        }
Пример #2
0
        public static void Update(Student Student)
        {
            _command = new SqlCommand("update StudentList set StudentID = @StudentID, Name= @Name, Gender = @Gender, [Group] = @Group where SerialNo=@SerialNo");

            _command.Parameters.AddWithValue("@StudentID", Student.StudentID);
            _command.Parameters.AddWithValue("@Name", Student.Name);
            _command.Parameters.AddWithValue("@Gender", Student.Gender);
            _command.Parameters.AddWithValue("@Group", Student.Group);
            _command.Parameters.AddWithValue("@SerialNo", Student.SerialNo);
            try
            {
                _connection.Open();
                _transaction = _connection.BeginTransaction();

                _command.Connection  = _connection;
                _command.Transaction = _transaction;

                _command.ExecuteNonQuery();

                DalCourse.Delete(true, Student.StudentID, _connection, _transaction);

                foreach (var course in Student.Courses)
                {
                    DalCourse.Insert(true, course, _connection, _transaction);
                }

                _transaction.Commit();
                _connection.Close();
            }
            catch (Exception ex)
            {
                _transaction.Rollback();
                _connection.Close();
                throw ex;
            }
        }