private void deleteBtn_Click(object sender, EventArgs e) { try { var confirmResult = MessageBox.Show("Сигурни ли сте, че искате да изтриете записа?", "Потвърждение!!", MessageBoxButtons.YesNo); if (confirmResult == DialogResult.Yes) { con.Open(); SqlCommand cmd = con.CreateCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = @"DELETE from CourseProfessionalField WHERE ProfessinalFieldID = '" + dataGridView1.CurrentRow.Cells[0].Value.ToString() + "' AND CourseID = '" + label3.Text + "'"; cmd.ExecuteNonQuery(); con.Close(); MessageBox.Show("Успешно изтрити данни!"); EditProfesionalField srch = new EditProfesionalField(label1.Text, label3.Text); srch.MdiParent = this.MdiParent; srch.Show(); this.Hide(); } } catch { MessageBox.Show("Невалидна команда!"); } }
private void editProfFieldBtn_Click(object sender, EventArgs e) { EditProfesionalField srch = new EditProfesionalField(nameCTxt.Text, noTxt.Text); srch.MdiParent = this.MdiParent; srch.Show(); }
private void addBtn_Click(object sender, EventArgs e) { try { con.Open(); SqlCommand cmd = con.CreateCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = @"insert into CourseProfessionalField(ProfessinalFieldID, CourseID) values('" + profFieldCmb.SelectedValue + "', '" + label3.Text + "')"; cmd.ExecuteNonQuery(); con.Close(); MessageBox.Show("Успешно добавени данни!"); EditProfesionalField srch = new EditProfesionalField(label1.Text, label3.Text); srch.MdiParent = this.MdiParent; srch.Show(); this.Hide(); } catch { MessageBox.Show($"{profFieldCmb.Text} вече съществува!"); } }