예제 #1
0
        private void btnadd_Click(object sender, EventArgs e)
        {
            addstudent add = new addstudent();

            add.Show();
            this.Hide();
        }
예제 #2
0
        private void btnsubmit_Click(object sender, EventArgs e)
        {
            string query = "INSERT INTO addstudent(firstname, othername, regno, idno, yearofstudy, course, email, phoneno, address, gender) VALUES('" + txtfname.Text + "','" + txtoname.Text + "','" + txtreg.Text + "','" + txtidno.Text + "','" + txtyear.Text + "','" + cmbcourse.SelectedItem + "','" + txtemail.Text + "','" + txtphone.Text + "','" + txtaddress.Text + "','" + gender + "')";

            if ((txtfname.Text.Length > 0) && (txtoname.Text.Length > 0) && (txtreg.Text.Length >= 4) && (txtemail.Text.Contains("@")) && (txtyear.Text.Length > 0) && (txtphone.Text.Length >= 8) && (txtidno.Text.Length >= 7) && (txtaddress.Text.Length >= 4) && (txtfname.Text.Length > 0))
            {
                try
                {
                    if (this.OpenConnection() == true)
                    {
                        MySqlCommand cmd = new MySqlCommand(query, connection);
                        cmd.ExecuteNonQuery();
                        MessageBox.Show("Your details added successfully!!. Thank you.", "STUDENT DETAILS ADDED SUCCESSFULLY!!!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        this.closeConnection();
                        txtaddress.Text = "";
                        txtemail.Text   = "";
                        txtfname.Text   = "";
                        txtidno.Text    = "";
                        txtoname.Text   = "";
                        txtphone.Text   = "";
                        txtreg.Text     = "";
                        txtyear.Text    = "";
                        cmbcourse.Text  = "";
                        addstudent add = new addstudent();
                        add.Show();
                        this.Hide();
                    }
                    else
                    {
                        MessageBox.Show("Details not added. Check the connection and try again.");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    this.closeConnection();
                }
            }
            else
            {
                MessageBox.Show("Make your entries valid!");
            }
        }