public bool UdateMemberType(MemberType memberType)
        {
            MySqlConnection cnn = DBUtility.getConnection();
            if (cnn != null)
            {
                try
                {
                    cnn.Open();
                    const string SQL = @"UPDATE 
											membertypes 
										SET 
											membertypename = @membertypename 
										WHERE 
											membertypeid = @membertypeid";
                    MySqlCommand command = new MySqlCommand(SQL, cnn);
                    command.Prepare();
                    command.Parameters.AddWithValue("@membertypename", memberType.MemberTypeName);
                    command.Parameters.AddWithValue("@membertypeid", memberType.MemberTypeId);
                    if (command.ExecuteNonQuery() > 0)
                    {
                        return true;
                    }
                }
                catch (MySqlException e)
                {
                    Console.WriteLine(e);
                }
                finally
                {
                    cnn.Close();
                }
            }
            return false;
        }
 private void btnSave_Click(object sender, EventArgs e)
 {
     if (id == 0)
     {
         if (txtTitle.Text == "")
         {
             MessageBox.Show("សូមបំពេញពត៏មានឲ្យបានត្រឹមត្រូវ!!!");
         }
         else
         {
             DTO.MemberType memberType = new MemberType(txtTitle.Text);
           
             if (new MemberTypeDAO().AddMemberType(memberType))
             {
                 txtTitle.Clear();
                 dgvMemberType.DataSource = new DAO.MemberTypeDAO().GetAllMemberTypes().Tables[0];
                 id = 0;
             }
             else
             {
                 MessageBox.Show("ប្រតិបត្តិការណ៍បរាជ័យ!!!");
             }
         }
     }
     else
     {
         DTO.MemberType memebrType = new DTO.MemberType(id, txtTitle.Text);
         if (new MemberTypeDAO().UdateMemberType(memebrType))
         {
             txtTitle.Clear();
             dgvMemberType.DataSource = new DAO.MemberTypeDAO().GetAllMemberTypes().Tables[0];
             id = 0;
             btnDelete.Visible = false;
         }
         else
         {
             MessageBox.Show("ប្រតិបត្តិការណ៍បរាជ័យ!!!");
         }
     }
 }
        public bool AddMemberType(MemberType memberType)
        {
            MySqlConnection cnn = DBUtility.getConnection();
            if (cnn != null)
            {
                cnn.Open();
                MySqlTransaction transaction = cnn.BeginTransaction();
                try
                {
                    const string SQL = @"INSERT INTO 
											membertypes(
												membertypename
											) 
										VALUES(
											@membertypename
										);";
                    MySqlCommand command = new MySqlCommand(SQL, cnn);
                    command.Prepare();
                    command.Parameters.AddWithValue("@membertypename", memberType.MemberTypeName);
                    if (command.ExecuteNonQuery() > 0)
                    {
                        transaction.Commit();
                        return true;
                    }
                }
                catch (MySqlException e)
                {
                    Console.WriteLine(e);
                    transaction.Rollback();
                }
                finally
                {
                    cnn.Close();
                }
            }
            return false;
        }