public void addEmployee(String password, String fname, String lname, String secret, String answer) { EmployeeAdd employees1 = new EmployeeAdd() { password = password, FirstName = fname, LastName = lname, SecretQuestion = secret, Answer = answer }; if (fname == "" || lname == "" || secret == "" || answer == "" || password == "") { MessageBox.Show(" First Name, Last Name, Secret Question, Answer, and Password are required. Employee was not added."); } else { employeemodel.AddEmployee(employees1); } }
internal void AddEmployee(EmployeeAdd employees) { string connectionString = ConfigurationManager.ConnectionStrings["MovieRental"].ConnectionString; string queryString = @"Insert into EMPLOYEE (PASSWORD,EMPLOYEE_FNAME,EMPLOYEE_LNAME,SECRET_QUESTION,ANSWER) values(@PASSWORD, @EMPLOYEE_FNAME, @EMPLOYEE_LNAME, @SECRET_QUESTION, @ANSWER)"; using (var connection = new SqlConnection(connectionString)) { connection.Open(); SqlCommand cmd2 = new SqlCommand(); try { cmd2 = new SqlCommand(queryString, connection); cmd2.Parameters.AddWithValue("@PASSWORD", employees.password); cmd2.Parameters.AddWithValue("@EMPLOYEE_FNAME", employees.FirstName); cmd2.Parameters.AddWithValue("@EMPLOYEE_LNAME", employees.LastName); cmd2.Parameters.AddWithValue("@SECRET_QUESTION", employees.SecretQuestion); cmd2.Parameters.AddWithValue("@ANSWER", employees.Answer); cmd2.ExecuteNonQuery(); MessageBox.Show(employees.FirstName + " " + employees.LastName + " " + "was successfully added."); connection.Close(); } catch (Exception e) { MessageBox.Show(e.Message); MessageBox.Show("Emloyee was not added"); connection.Close(); } } }// end of add employee