Создание веб-приложения, сочетающего в себе проектирование и создание баз данных, работу со сторонними форматами данных, программирование в NET и веб-разработку, страница 62

                else

                {

                    //ОБЪЯВЛЯЕМ

                    MySqlCommand comm;

                    conn = new MySqlConnection(connectionString);

                    conn.Open();

                    string sql;

                    //УДАЛЯЕМ РОЛЬ

                    sql = "DELETE FROM roles WHERE name = '" + roleName + "';";

                    comm = new MySqlCommand(sql, conn);

                    comm.ExecuteNonQuery();

                    conn.Close();

                    return true;

                }

            }

            catch (MySqlException exp)

            {

                conn.Close();

                return false;

            }

            catch (ProviderException exp)

            {

                conn.Close();

                return false;

            }

        }

        //вовзращает массив с именами пользователей.

        public override string[] FindUsersInRole(string roleName, string usernameToMatch)

        {

             MySqlConnection conn = null;

             try

             {

                 if (roleName == null || roleName == "" || usernameToMatch == null || usernameToMatch == "") throw new ProviderException();

                 else

                 {

                     //ОБЪЯВЛЯЕМ

                     conn = new MySqlConnection(connectionString);

                     conn.Open();

                     int id_role = 0;

                     string sql = "";

                     string[] users_in_role;

                     MySqlDataReader reader = null;

                     MySqlCommand comm = null;

                     MySqlDataAdapter adapter = null;

                     DataSet data = new DataSet();

                     //ДОСТАЕМ ID РОЛИ

                     sql = "SELECT id FROM roles WHERE name = '" + roleName + "';";

                     comm = new MySqlCommand(sql, conn);

                     reader = comm.ExecuteReader();

                     while (reader.Read())

                     {

                         id_role = Convert.ToInt32(reader[0].ToString());

                     }

                     reader.Close();

                     //СРАВНИВАЕМ ПОЛУЧЕНЫЙ ID С РОЛЬЮ ПОЛЬЗОВАТЕЛЯ

                     if (id_role == 0) throw new ProviderException();

                     else

                     {

                         sql = "SELECT name FROM auth_user WHERE role =" + id_role + ";";

                         adapter = new MySqlDataAdapter(sql, conn);

                         data = new DataSet();

                         adapter.Fill(data);

                         if (data.Tables[0].Rows.Count == 0) throw new ProviderException();

                         else

                         {

                             users_in_role = new string[data.Tables[0].Rows.Count];

                             for (int i = 0; i < users_in_role.Length; i++)

                             {

                                 users_in_role[i] = data.Tables[0].Rows[i]["name"].ToString();

                             }

                             conn.Close();

                             return users_in_role;

                         }

                     }

                 }

             }

             catch (MySqlException exp)

             {

                 conn.Close();

                 return null;

             }

             catch (ProviderException exp)

             {

                 conn.Close();

                 return null;

             }

        }

        //возвращает массив с названиями ролей

        public override string[] GetAllRoles()

        {

            MySqlConnection conn = null;

            try

            {

                    //ОБЪЯВЛЕНИЕ

                    conn = new MySqlConnection(connectionString);

                    conn.Open();