示例#1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (tbID.Text == "")
            {
                errorProvider1.SetError(tbID, "Pleaste insert ID!");
            }
            else
            if (tbF.Text == "")
            {
                errorProvider1.SetError(tbF, "Insert your first name!");
            }
            else
            if (tbL.Text == "")
            {
                errorProvider1.SetError(tbL, "Insert your last name!");
            }
            else
            if (cbAge.Text == "")
            {
                errorProvider1.SetError(cbAge, "Please choose your age!");
            }
            else
            {
                try
                {
                    OleDbConnection connection = new OleDbConnection(connS);
                    connection.Open();
                    OleDbCommand comanda = new OleDbCommand();
                    comanda.Connection = connection;

                    comanda.CommandText = "INSERT INTO employees VALUES(?,?,?,?,?)";
                    comanda.Parameters.Add("ID", OleDbType.Integer).Value             = Convert.ToInt32(tbID.Text);
                    comanda.Parameters.Add("First name", OleDbType.Char, 30).Value    = tbF.Text;
                    comanda.Parameters.Add("Last name", OleDbType.Char, 50).Value     = tbL.Text;
                    comanda.Parameters.Add("Employment date", OleDbType.DBDate).Value = dtpE.Value;
                    comanda.Parameters.Add("Age", OleDbType.Integer).Value            = Convert.ToInt32(cbAge.Text);

                    comanda.ExecuteNonQuery();

                    MessageBox.Show("Employee has been added!");

                    this.Close();
                    ViewEmployees frm = new ViewEmployees();
                    frm.Show();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Exception: " + ex.Message);
                }
            }
        }
示例#2
0
        private void button1_Click(object sender, EventArgs e)
        {
            ViewEmployees frm = new ViewEmployees();

            frm.ShowDialog();
        }