コード例 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            this.Hide();
            employeeView ev = new employeeView();

            ev.Show();
        }
コード例 #2
0
 private void button1_Click(object sender, EventArgs e)
 {
     String full = fullname.Text;
     String last = lastname.Text;
     String da = dob.Value.ToString("MM/dd/yyyy");
     String pho = phone.Text;
     String gen = "";
     if (male.Checked)
     {
         gen = "Male";
     }
     if (female.Checked)
     {
         gen = "Female";
     }
     Double sal = Convert.ToDouble(salary.Text);
     String ni = nic.Text;
     String add = address.Text;
     if (full == "" || last == "" || da =="" || pho =="" || gen =="" || ni == "" || add == "")
     {
         MessageBox.Show("Every Field are Required");
     }
     else
     {
         DateTime tod = DateTime.Today;
         string connectionString = "datasource=127.0.0.1;port=3306;username=root;password=;database=debuggeddb;";
         MySqlConnection databaseConnection = new MySqlConnection(connectionString);
         try
         {
             databaseConnection.Open();
             MySqlCommand comm = databaseConnection.CreateCommand();
             comm.CommandText = "INSERT INTO employeetable(`FirstName`,`LastName`,`DOB`,`NIC`,`Gender`,`Address`,`Salary`,`PhoneNo`,`AppDate`) VALUES(@ff,@ll,@dd,@nn,@gg,@aa,@ss,@pp,@ap);";
             comm.Parameters.AddWithValue("@ff", full);
             comm.Parameters.AddWithValue("@ll", last);
             comm.Parameters.AddWithValue("@dd", da);
             comm.Parameters.AddWithValue("@nn", ni);
             comm.Parameters.AddWithValue("@gg", gen);
             comm.Parameters.AddWithValue("@aa", add);
             comm.Parameters.AddWithValue("@ss", sal);
             comm.Parameters.AddWithValue("@pp", pho);
             comm.Parameters.AddWithValue("@ap", tod);
             comm.ExecuteNonQuery();
             databaseConnection.Close();
             //clear the text
             fullname.Text = "";
             lastname.Text = "";
             phone.Text = "";
             salary.Text = "";
             nic.Text = "";
             address.Text = "";
             //message
             MessageBox.Show("Data Has been successfully inserted");
             this.Hide();
             employeeView ev = new employeeView();
             ev.Show();
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
 }