public int addProfessor(professor nProfessor) { try { connection.ConnectionString = c; connection.Open(); OleDbCommand command = new OleDbCommand(); command.Connection = connection; string query = "insert into Professor ([ProfessorID],[FName],[LName],[ClassTeaching]) values('" + nProfessor.getID + "','" + nProfessor.getfirstName + "','" + nProfessor.getlastName + "','" + nProfessor.getClass + "')"; command.CommandText = query; command.ExecuteNonQuery(); connection.Close(); return(1); } catch (Exception ex) { string test = "Doesnt Work" + ex; return(-1); } }
private void btnAddP_Click(object sender, EventArgs e) { int test; bool result; if ((result = int.TryParse(txtpID.Text, out test) == false)) { MessageBox.Show("Professor ID Must be interger!", "", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { int professorID = Convert.ToInt32(txtpID.Text); string professorFN = txtpFN.Text; string professorLN = txtpLN.Text; string professorCT = txtCT.Text; professor nProfessor = new professor(professorID, professorFN, professorLN, professorCT); int value = Data.addProfessor(nProfessor); if (value == 1) { txtpID.Text = ""; txtpFN.Text = ""; txtpLN.Text = ""; txtCT.Text = ""; MessageBox.Show("Professor Data Added", "", MessageBoxButtons.OK); } else { MessageBox.Show("Duplicate ID Number!!, Please restart this form again to enter correct one.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }