private void buttonEditPK_Click(object sender, EventArgs e) { int id = 0; try { id = Convert.ToInt32(dataGridView3[0, dataGridView3.CurrentRow.Index].Value.ToString()); } catch (NullReferenceException) { } FormPersonalKeeled dlg = new FormPersonalKeeled("Edit entry", "Edit PersonalKeeled", "Save", id); if (dlg.ShowDialog() == DialogResult.OK) { Database db = new Database(); db.open(); if (db.Connected) { try { db.cmd_exec("UPDATE [dbo].[PersonalKeeled]" + " SET idPersonal = '" + dlg.IdP + "', idKeeled = '" + dlg.IdK + "', Tase = '" + dlg.Tase + "'" + " WHERE Id = '" + dlg.Id + "'"); } catch (Exception) { MessageBox.Show("Entry edit fail!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); } db.close(); buttonRefreshPK_Click(sender, e); } } }
private void buttonAddPK_Click(object sender, EventArgs e) { FormPersonalKeeled dlg = new FormPersonalKeeled("New entry", "Add to PersonalKeeled", "Add", 0); if (dlg.ShowDialog() == DialogResult.OK) { Database db = new Database(); db.open(); MessageBox.Show("INSERT INTO [dbo].[PersonalKeeled] (idPersonal, idKeeled, Tase)" + " VALUES('" + dlg.IdP + "', '" + dlg.IdK + "', '" + dlg.Tase + "')"); if (db.Connected) { try { db.cmd_exec("INSERT INTO [dbo].[PersonalKeeled] (idPersonal, idKeeled, Tase)" + " VALUES('" + dlg.IdP + "', '" + dlg.IdK + "', '" + dlg.Tase + "')"); } catch (Exception) { MessageBox.Show("Entry add fail!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); } db.close(); buttonRefreshPK_Click(sender, e); } } }