Jason Kleinhans

Jason Kleinhans

  • NA
  • 7
  • 4.5k

the method of operation is not implemented

Jul 9 2021 6:10 PM

when trying to add a member data to MySQL database, i get the following error the method of operation is not implemented

Below is the code for my RegisterForm.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Student_Management_System
{
    public partial class RegisterForm : Form
    {
        MemberClass member = new MemberClass();
        public RegisterForm()
        {
            InitializeComponent();
        }

      
        private void RegisterForm_Load(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button_add_Click(object sender, EventArgs e)
        {
            //add new member
            string FirstName = txtFirstName.Text;
            string LastName = txtLastName.Text;
            DateTime BirthDate = dateTime_DOB.Value;
            string Age = comboBox_age.Text;
            string Gender = radioButton_male.Checked ? "Male" : "Female";
            string Email = txtEmail.Text;
            string Telephone = txtPhone.Text;
            string Cellphone = txtcellphone.Text;
            string Address = txtaddress.Text;
            string Occupation = txtOccupation.Text;
            string MaritalStatus = comboBox_maritalstatus.Text;
            DateTime DateOfMarriage = dateTime_MarriageDate.Value;
            DateTime DateOfMembership = dateTime_MemDate.Value;
            DateTime DateOfBaptism = dateTime_BaptismDate.Value;
            string CellGroup = comboBox_cellgroup.Text;
            string MissionGroup = comboBox_missiongroup.Text;
            string WhatsApp = comboBox_whatsapp.Text;


            //we need to check member's age between 16 and 100
            int born_year = dateTime_DOB.Value.Year;
            int this_year = DateTime.Now.Year;
            if ((this_year - born_year) < 16 || (this_year - born_year) > 100)
            {
                MessageBox.Show("The member's age must be between 16 and 100", "Invalid Birthdate", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (verify())
            {
                try

                {
                    if (member.insertMember(FirstName, LastName, Age, BirthDate, Gender, Email, Telephone, Cellphone, Address, Occupation, MaritalStatus, DateOfMarriage, DateOfMembership, DateOfBaptism, CellGroup, MissionGroup, WhatsApp))
                    {

                        MessageBox.Show("New Member Added", "Add Member", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }catch(Exception ex)
                
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Empty Field", "Add Member", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                
            }


        }
        //create a function to verify
        bool verify()
        {
            if ((txtFirstName.Text == "") || (txtLastName.Text == "") ||
                (txtaddress.Text == "") || (txtPhone.Text == ""))
                {
                return false;
            }
            else
                return true;
        }
        private void button_clear_Click(object sender, EventArgs e)
        {

        }

        
    }
}
 

My Code for MemberClass.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;
using System.Windows.Forms;


namespace Student_Management_System
{
    class MemberClass
    {
        DBConnect connect = new DBConnect();
        //create a function to add a new member to the database
        public bool insertMember(string FirstName, string LastName, DateTime BirthDate, string Age, string Gender, string Email, string Telephone, string Cellphone, string Address, string Occupation, string MaritalStatus, DateTime DateOfMarriage, DateTime DateOfMembership, DateTime DateOfBaptism, string CellGroup, string MissionGroup, string WhatsApp)
          {


            MySqlCommand command = new MySqlCommand("INSERT INTO `membership`(`FirstName`, `LastName`, `BirthDate`, `Age`, `Gender`, `Email`, `Telephone`, `Cellphone`, `Address`, `Occupation`, `MaritalStatus`, `DateOfMarriage`, `DateOfMembership`, `DateOfBaptism`, `CellGroup`, `MissionGroup`, `WhatsApp`) VALUES(@FirstName, @LastName, @Age, @Gender, @Email, @Phone, @Cellphone, @Address, @Occupation, @MaritalStatus, @DateOfMarriage, @DateOfMembership, @DateOfBaptism, @CellGroup, @MissionGroup, @WhatsApp)", connect.getconnection);

            //@fn, @ln, @bd, @age, @gen, @em, @ph, @cell, @adr, @occu, @ms, @domar, @domem, @dobap, @cgr, @missg, @wa

            command.Parameters.Add("", MySqlDbType.VarChar).Value = FirstName;
            command.Parameters.Add("", MySqlDbType.VarChar).Value = LastName;
            command.Parameters.Add("", MySqlDbType.VarChar).Value = BirthDate;
            command.Parameters.Add("", MySqlDbType.VarChar).Value = Age;
            command.Parameters.Add("", MySqlDbType.VarChar).Value = Gender;
            command.Parameters.Add("", MySqlDbType.VarChar).Value = Email;
            command.Parameters.Add("", MySqlDbType.VarChar).Value = Telephone;
            command.Parameters.Add("", MySqlDbType.VarChar).Value = Cellphone;
            command.Parameters.Add("", MySqlDbType.VarChar).Value = Address;
            command.Parameters.Add("", MySqlDbType.VarChar).Value = Occupation;
            command.Parameters.Add("", MySqlDbType.VarChar).Value = MaritalStatus;
            command.Parameters.Add("", MySqlDbType.VarChar).Value = DateOfMarriage;
            command.Parameters.Add("", MySqlDbType.VarChar).Value = DateOfMembership;
            command.Parameters.Add("", MySqlDbType.VarChar).Value = DateOfBaptism;
            command.Parameters.Add("", MySqlDbType.VarChar).Value = CellGroup;
            command.Parameters.Add("", MySqlDbType.VarChar).Value = MissionGroup;
            command.Parameters.Add("", MySqlDbType.VarChar).Value = WhatsApp;

            connect.openConnect();
            if(command.ExecuteNonQuery()==1)
            {
                connect.closeConnect();
                return true;
            }
            else
            {
                connect.closeConnect();
                return false;
            }

        }

        internal bool insertMember(string FirstName, string LastName, string Age, DateTime BirthDate, string Gender, string Email, string Telephone, string Cellphone, string Address, string Occupation, string MaritalStatus, DateTime DateOfMarriage, DateTime DateOfMembership, DateTime DateOfBaptism, string CellGroup, string MissionGroup, string WhatsApp)
        {
            throw new NotImplementedException();
        }
    }
}
 

 


Answers (1)