Ejemplo n.º 1
0
        // Обновляем информацию об ученике в БД (класс изменяется).
        public static void UpdatePupilWithClass(int pupilId, string name, string surname, string patronymic, int classID)
        {
            PupilFullInformation pupil = new PupilFullInformation();

            string connectionString = @"Data Source=DESKTOP-81JSABO\SQLEXPRESS;Initial Catalog=ElectronicJournal;Integrated Security=True";
            string sqlExpression    = "[sp_UpdatePupilInf]";

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();
                SqlCommand command = new SqlCommand(sqlExpression, connection);

                command.CommandType = System.Data.CommandType.StoredProcedure;

                SqlParameter pupilIDParam = new SqlParameter
                {
                    ParameterName = "@Pupil_ID",
                    Value         = pupilId
                };

                SqlParameter pupilNameParam = new SqlParameter
                {
                    ParameterName = "@Name",
                    Value         = name
                };

                SqlParameter pupilSurnameParam = new SqlParameter
                {
                    ParameterName = "@Surname",
                    Value         = surname
                };

                SqlParameter pupilPatronymicParam = new SqlParameter
                {
                    ParameterName = "@Patronymic",
                    Value         = patronymic
                };

                SqlParameter pupilClassIDParam = new SqlParameter
                {
                    ParameterName = "@Class_ID",
                    Value         = classID
                };

                command.Parameters.Add(pupilIDParam);
                command.Parameters.Add(pupilNameParam);
                command.Parameters.Add(pupilSurnameParam);
                command.Parameters.Add(pupilPatronymicParam);
                command.Parameters.Add(pupilClassIDParam);

                command.ExecuteNonQuery();
            }
        }
Ejemplo n.º 2
0
        // Получаем полную информацыю об ученике из БД.
        public static PupilFullInformation GetPupilsFullInformation(int ID)
        {
            PupilFullInformation pupil = new PupilFullInformation();

            string connectionString = @"Data Source=DESKTOP-81JSABO\SQLEXPRESS;Initial Catalog=ElectronicJournal;Integrated Security=True";
            string sqlExpression    = "sp_GetFullInformation";

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();
                SqlCommand command = new SqlCommand(sqlExpression, connection);

                command.CommandType = System.Data.CommandType.StoredProcedure;

                SqlParameter nameParam = new SqlParameter
                {
                    ParameterName = "@Pupil_ID",
                    Value         = ID
                };

                command.Parameters.Add(nameParam);

                SqlDataReader reader = command.ExecuteReader();

                if (reader.HasRows)
                {
                    while (reader.Read()) // построчно считываем данные
                    {
                        int      id            = reader.GetInt32(0);
                        string   name          = reader.GetString(1);
                        string   surname       = reader.GetString(2);
                        string   patronymic    = reader.GetString(3);
                        string   pupilClass    = reader.GetString(4);
                        DateTime date_Of_Birth = reader.GetDateTime(5);
                        int      age           = reader.GetInt32(6);
                        string   pupil_Phone   = reader.GetString(7);
                        string   parent_Phone  = reader.GetString(8);
                        string   address       = reader.GetString(9);

                        pupil = new PupilFullInformation(id, name, surname, patronymic, pupilClass, date_Of_Birth, age, pupil_Phone, parent_Phone, address);
                    }
                }

                reader.Close();
            }

            return(pupil);
        }