private void Add_btn_Click_1(object sender, EventArgs e) { StudentFunction stuf = new StudentFunction(); int id = Convert.ToInt32(Id_txt.Text); string fname = FirstName_txt.Text; string lname = LastName_txt.Text; DateTime bdate = dateTimePicker1.Value; string phone = Phone_txt.Text; string adrs = Address_txt.Text; string gender = "Male"; if (Gender2.Checked) { gender = "Female"; } MemoryStream picture = new MemoryStream(); int born_year = dateTimePicker1.Value.Year; int this_year = DateTime.Now.Year; if (((this_year - born_year) < 10 || (this_year - born_year) > 100)) { MessageBox.Show("The student age must between 10 and 100 years old", "Invalid Birth Date", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (Verify()) { pictureBox1.Image.Save(picture, pictureBox1.Image.RawFormat); if (stuf.insertStudent(id, fname, lname, bdate, gender, phone, adrs, picture)) { MessageBox.Show("New student added successfully!", "Add student", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Error!", "Add student", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Empty fields", "Add student", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }